:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-well: #fafbfc;
  --text: #2b2f36;
  --text-muted: #6b7280;
  --text-dim: #8e96a0;
  --border: #e5e7eb;
  --border-soft: #eef0f3;
  --up: #a5243d;
  --up-soft: #fbecec;
  --down: #527a66;
  --down-soft: #e8f0ec;
  --flat: #8e96a0;
  --brand: #c73532;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-card: 0 8px 28px rgba(16, 24, 40, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* 动效规范 v2 · Coordinte §4 / §7 */
  --motion-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --motion-fog-ms: 320ms;
  --motion-fog-blur: 14px;
  --motion-rank-ms: 220ms;
  --motion-rank-stagger: 40ms;
  --motion-entrance-flight-ms: 480ms;
  --motion-entrance-min-ms: 400ms;
  --entrance-logo-size: 108px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-soft);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
    "Helvetica Neue", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { overflow-x: hidden; }

.app {
  max-width: 420px;
  margin: 0 auto;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  padding-bottom: calc(44px + var(--safe-bottom));
}

/* ---- Top bar ---- */
.topbar {
  flex-shrink: 0;
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: block;
  flex-shrink: 0;
}

/* Topbar mark reserved until entrance flight seats */
body.has-entrance-gate .brand-mark {
  visibility: hidden;
}
body.has-entrance-gate .brand-mark.is-seated {
  visibility: visible;
}


.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }

.brand-zh {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.brand-en {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.demo-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  letter-spacing: 0.02em;
}

.back-btn {
  display: none;
  align-items: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 2px;
  margin-right: 4px;
}

.back-btn.visible { display: inline-flex; }
.back-btn svg { width: 16px; height: 16px; }

.sub-heading {
  display: none;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sub-heading.visible { display: block; }
.brand.sub-mode .brand-mark { display: none; }

/* ---- Segmented control ---- */
.seg-wrap {
  flex-shrink: 0;
  padding: 12px 16px 0;
}

.seg {
  display: flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg button {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-muted);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.seg button.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
  font-weight: 650;
}

.switch-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 8px 16px 0;
  letter-spacing: 0.02em;
}

/* ---- Axis meaning strip ---- */
.axis-strip {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 16px 6px;
  flex-wrap: wrap;
}

.axis-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
}

.axis-chip strong {
  color: var(--brand);
  font-weight: 650;
}

.axis-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
  opacity: 0.7;
}

/* ---- Story highlight ---- */
.story {
  flex-shrink: 0;
  margin: 6px 16px 0;
  padding: 10px 12px;
  background: var(--up-soft);
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  display: none;
}

.story.visible { display: block; }

.story-label {
  font-size: 10px;
  font-weight: 650;
  color: var(--up);
  letter-spacing: 0.06em;
  margin-bottom: 3px;
}

/* ---- Chart area ---- */
.chart-wrap {
  flex: 1;
  position: relative;
  min-height: 380px;
  margin: 8px 12px 0;
  border-radius: var(--radius-lg);
  background: var(--bg-well);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  touch-action: manipulation;
}

/* §4 fog veil — chart only; topbar / badge / disclaimer stay sharp */
.chart-fog {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
  border-radius: inherit;
  background: rgba(250, 251, 252, 0.12);
  backdrop-filter: blur(var(--motion-fog-blur));
  -webkit-backdrop-filter: blur(var(--motion-fog-blur));
  opacity: 0;
  transition: opacity var(--motion-fog-ms) var(--motion-ease);
}

.chart-wrap.is-fogged .chart-fog,
.chart-wrap.is-cold-fog .chart-fog {
  opacity: 1;
}

.view-panel {
  position: absolute;
  inset: 0;
  display: none;
  transition: filter var(--motion-fog-ms) var(--motion-ease);
}
.view-panel.active { display: block; }

/* filter fallback / complement (spec: backdrop-filter + filter 同值) */
.chart-wrap.is-fogged .view-panel,
.chart-wrap.is-cold-fog .view-panel {
  filter: blur(var(--motion-fog-blur));
}

#barPanel {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 12px;
}

/* ---- Bar / rank list ---- */
.rank-list {
  list-style: none;
  padding: 0 12px;
}

.rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(6px);
  transition:
    background 0.12s,
    opacity var(--motion-rank-ms) var(--motion-ease),
    transform var(--motion-rank-ms) var(--motion-ease);
  transition-delay: 0ms, var(--stagger, 0ms), var(--stagger, 0ms);
}

.rank-list.is-entered .rank-item {
  opacity: 1;
  transform: none;
}

.rank-item:active,
.rank-item.story-hit { background: rgba(165, 36, 61, 0.06); }

.rank-num {
  width: 22px;
  font-size: 12px;
  font-weight: 650;
  color: var(--text-dim);
  text-align: center;
  flex-shrink: 0;
}

.rank-num.top { color: var(--up); }

.rank-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-bar-track {
  width: 88px;
  height: 6px;
  background: var(--border-soft);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.rank-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--up);
  opacity: 0.85;
}

.rank-val {
  width: 36px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.rank-delta {
  width: 48px;
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.rank-delta.up { color: var(--up); }
.rank-delta.down { color: var(--down); }
.rank-delta.flat { color: var(--flat); }

/* ---- Legend ---- */
.legend {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 8px 16px 0;
  font-size: 10px;
  color: var(--text-dim);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.legend .up i { background: var(--up); }
.legend .down i { background: var(--down); }
.legend .flat i { background: var(--flat); }

/* ---- Hint + footer ---- */
.hint {
  flex-shrink: 0;
  padding: 10px 16px 4px;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
}

.page-footer {
  flex-shrink: 0;
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  padding: 4px 16px 8px;
  letter-spacing: 0.01em;
}

.sticky-disclaimer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 215;
  text-align: center;
  padding: 7px 12px calc(7px + var(--safe-bottom));
  font-size: 12px;
  line-height: 1.4;
  color: #5c3d00;
  background: rgba(255, 243, 205, 0.96);
  border-top: 1px solid rgba(196, 140, 0, 0.35);
  letter-spacing: 0.02em;
  pointer-events: none;
}

/* ---- Info card sheet ---- */
.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 24, 0.28);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-fog-ms) var(--motion-ease);
}

.sheet-mask.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) translateY(110%);
  width: 100%;
  max-width: 420px;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow-card);
  z-index: 210;
  padding: 12px 18px calc(18px + var(--safe-bottom) + 28px);
  opacity: 0;
  transition:
    transform var(--motion-fog-ms) var(--motion-ease),
    opacity var(--motion-fog-ms) var(--motion-ease);
}

.sheet.open {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 0 auto 12px;
}

.sheet-title {
  font-size: 17px;
  font-weight: 650;
  margin-bottom: 2px;
}

.sheet-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.sheet-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.metric {
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 10px 12px;
}

.metric-label {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.metric-val {
  font-size: 18px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

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

.sheet-note {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.55;
  background: var(--bg-well);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 10px 12px;
}

.sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.sheet-actions button {
  flex: 1;
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.sheet-actions .secondary {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text-muted);
  flex: 1;
}

.sheet-actions #sheetDrill[hidden],
.sheet-actions #sheetDrill[style*="display: none"] {
  display: none !important;
}


/* ---- Logo click entrance gate (动效规范 v3) ---- */
.entrance-gate {
  position: fixed;
  inset: 0;
  z-index: 180; /* below sticky-disclaimer (215) & guide (300); above app */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  /* Stage A: opaque splash — 未点击前不进入清晰图区 */
  background: #fafbfc;
  outline: none;
  overflow: hidden;
  transition: background 280ms var(--motion-ease), opacity 280ms var(--motion-ease);
}

.entrance-gate.is-flying {
  /* Stage C: veil lifts so fogged chart shows; blur stays on chart-wrap */
  background: rgba(250, 251, 252, 0.18);
  pointer-events: none;
}

.entrance-gate.is-done {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.entrance-glow {
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(72vw, 340px);
  height: min(72vw, 340px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(199, 53, 50, 0.16) 0%, rgba(199, 53, 50, 0.05) 40%, transparent 70%);
  pointer-events: none;
  transition: opacity 280ms var(--motion-ease);
}

.entrance-gate.is-flying .entrance-glow {
  opacity: 0;
}

.entrance-center {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  text-align: center;
}

.entrance-mark {
  width: var(--entrance-logo-size);
  height: var(--entrance-logo-size);
  border-radius: 24px; /* ≈112/512 of 108 */
  display: block;
  flex-shrink: 0;
  box-shadow: 0 12px 40px rgba(199, 53, 50, 0.24);
  transform-origin: top left;
}

.entrance-word {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  transition: opacity 200ms var(--motion-ease);
}

.entrance-zh {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #2b2f36;
}

.entrance-en {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.22em;
  color: var(--brand);
  text-transform: uppercase;
}

.entrance-hint {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.14em;
  animation: entrance-hint-pulse 2.4s var(--motion-ease) infinite;
  transition: opacity 180ms var(--motion-ease);
}

.entrance-demo {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  transition: opacity 180ms var(--motion-ease);
}

@keyframes entrance-hint-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.entrance-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(52px + var(--safe-bottom));
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  pointer-events: none;
  transition: opacity 200ms var(--motion-ease);
}

.entrance-gate.is-flying .entrance-hint,
.entrance-gate.is-flying .entrance-demo,
.entrance-gate.is-flying .entrance-foot,
.entrance-gate.is-flying .entrance-word {
  opacity: 0;
}

.entrance-mark.is-flying {
  position: fixed;
  z-index: 190;
  margin: 0;
  box-shadow: 0 4px 16px rgba(199, 53, 50, 0.18);
  transition:
    left var(--entrance-flight-ms, var(--motion-entrance-flight-ms)) var(--motion-ease),
    top var(--entrance-flight-ms, var(--motion-entrance-flight-ms)) var(--motion-ease),
    width var(--entrance-flight-ms, var(--motion-entrance-flight-ms)) var(--motion-ease),
    height var(--entrance-flight-ms, var(--motion-entrance-flight-ms)) var(--motion-ease),
    border-radius var(--entrance-flight-ms, var(--motion-entrance-flight-ms)) var(--motion-ease),
    box-shadow var(--entrance-flight-ms, var(--motion-entrance-flight-ms)) var(--motion-ease);
}

/* ---- Guide overlay ---- */
.guide-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 24, 0.55);
  z-index: 300;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.guide-mask.open { display: flex; }

.guide-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(24px + var(--safe-bottom));
  box-shadow: var(--shadow-card);
}

.guide-kicker {
  font-size: 11px;
  font-weight: 650;
  color: var(--brand);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.guide-title {
  font-size: 18px;
  font-weight: 650;
  margin-bottom: 14px;
}

.guide-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.guide-steps li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.guide-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--up-soft);
  color: var(--up);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.guide-step-title {
  font-size: 13px;
  font-weight: 650;
  margin-bottom: 2px;
}

.guide-step-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.guide-btn {
  width: 100%;
  border: none;
  background: var(--brand);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 13px;
  border-radius: 12px;
  cursor: pointer;
}

.guide-skip {
  display: block;
  width: 100%;
  margin-top: 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 6px;
}

/* ---- Share stretch (optional) ---- */
.share-btn {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 15;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 550;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.chart-wrap .share-btn { display: inline-flex; }

.share-canvas-wrap {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 390px;
  pointer-events: none;
}

@media (min-width: 480px) {
  body { background: #eef0f3; padding: 24px 0; }
  .app {
    min-height: min(100dvh - 48px, 860px);
    height: min(100dvh - 48px, 860px);
    border-radius: 20px;
    box-shadow: 0 0 0 1px var(--border), 0 24px 80px rgba(16, 24, 40, 0.1);
    overflow: hidden;
  }
  .sticky-disclaimer {
    max-width: 420px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 0 0 20px 20px;
  }
  .sheet, .guide-card { border-radius: 18px; bottom: 24px; }
}

/* 动效规范 v2 · prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .chart-fog {
    transition-duration: 0.01ms;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: transparent;
  }
  .chart-wrap.is-fogged .chart-fog,
  .chart-wrap.is-cold-fog .chart-fog {
    opacity: 0;
  }
  .chart-wrap.is-fogged .view-panel,
  .chart-wrap.is-cold-fog .view-panel {
    filter: none;
    transition-duration: 0.01ms;
  }
  .rank-item {
    opacity: 1;
    transform: none;
    transition: background 0.12s, opacity 150ms ease;
    transition-delay: 0ms;
  }
  .sheet-mask,
  .sheet {
    transition-duration: 150ms;
  }

  .entrance-gate,
  .entrance-glow,
  .entrance-word,
  .entrance-hint,
  .entrance-foot,
  .entrance-mark.is-flying {
    transition-duration: 150ms !important;
    animation: none !important;
  }
  .entrance-hint { opacity: 0.85; }
}



/* Realname preview: asOf + 非实时 */
.asof-badge {
  display: inline-flex;
  align-items: center;
  max-width: 58vw;
  padding: 3px 8px;
  margin-right: 6px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #4b5563;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 1;
  min-width: 0;
}
