/* 深蓝画布 + 浅色卡片；详情弹层仍为浅色。A 股：涨红跌绿。 */
:root {
  --canvas-bg-top: #1e3d65;
  --canvas-bg-mid: #152f51;
  --canvas-bg-bottom: #0b1a2e;
  --wx-bg: var(--canvas-bg-mid);
  --wx-bg-page: #f6f7f9;
  --wx-surface: #ffffff;
  --wx-border: #c8d0dc;
  --wx-border-soft: #dce3ee;
  --wx-border-light: #eaf0f6;
  --wx-text: #1a2433;
  --wx-text-secondary: #3d4a5c;
  --wx-muted: #5c6b7f;
  --wx-link: #1e4d7b;
  --wx-green: #1b4a72;
  --wx-green-press: #153a59;
  /* A 股：涨红跌绿（饱和度略压低以贴近机构终端） */
  --rise: #b71c1c;
  --rise-bg: #fff8f8;
  --rise-border: #ffc9c9;
  --fall: #1b5e20;
  --fall-bg: #f4faf4;
  --fall-border: #c8e6c9;
  --accent-model: #1e4d7b;
  --accent-mark: #1b4a72;
  --focus: #1b4a72;
  --code: #2c5282;
  --card-tint-from: #feffff;
  --card-tint-mid: #f7fafc;
  --card-tint-to: #f0f5f9;
  --card-border-strong: rgba(15, 23, 42, 0.09);
  --card-divider: rgba(15, 23, 42, 0.08);
  --card-title-fg: #0a0e14;
  --card-body-fg: #141a22;
  --card-secondary-fg: #1f2937;
  --card-meta-fg: #4b5563;
  --card-code-fg: #0f4f6d;
  --radius: 16px;
  --radius-sheet: 12px;
  --shadow-card:
    0 0 0 1px rgba(255, 255, 255, 0.14),
    0 2px 8px rgba(0, 0, 0, 0.18),
    0 14px 36px rgba(0, 0, 0, 0.28);
  --font:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans SC",
    "Helvetica Neue", Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  height: -webkit-fill-available;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  background: linear-gradient(
    185deg,
    var(--canvas-bg-top) 0%,
    var(--canvas-bg-mid) 52%,
    var(--canvas-bg-bottom) 100%
  );
  background-attachment: fixed;
  color-scheme: dark;
  color: rgba(230, 238, 252, 0.88);
  line-height: 1.62;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  width: 100%;
}

.btn {
  font-family: inherit;
  font-size: 0.875rem;
  min-height: 44px;
  padding: 0.4rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--wx-border);
  background: var(--wx-surface);
  color: var(--wx-text);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s;
}

.btn:active {
  opacity: 0.85;
}

.btn-primary {
  background: var(--wx-green);
  border-color: var(--wx-green);
  color: #fff;
  font-weight: 500;
}

.btn-primary:active {
  background: var(--wx-green-press);
  border-color: var(--wx-green-press);
}

.btn-ghost {
  min-height: 44px;
  padding: 0.35rem 0.5rem;
  background: transparent;
  color: var(--wx-link);
  border-color: transparent;
  text-decoration: none;
  font-weight: 400;
}

.btn-ghost:active {
  opacity: 0.6;
}

.main-feed {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: transparent;
  width: 100%;
  min-width: 0;
}

.pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: transparent;
}

.pane-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.52rem 0.6rem 0.95rem;
  padding-left: max(0.6rem, env(safe-area-inset-left));
  padding-right: max(0.6rem, env(safe-area-inset-right));
  padding-top: max(0.52rem, env(safe-area-inset-top));
  padding-bottom: max(0.95rem, env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.pane-scroll .loading,
.pane-scroll .end {
  color: rgba(230, 238, 252, 0.65);
}

.news-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.52rem;
}

.card {
  color-scheme: light;
  background: linear-gradient(
    165deg,
    var(--card-tint-from) 0%,
    var(--card-tint-mid) 48%,
    var(--card-tint-to) 100%
  );
  border: 1px solid var(--card-border-strong);
  border-radius: var(--radius);
  padding: 0.68rem 0.76rem;
  color: var(--card-body-fg);
  box-shadow: var(--shadow-card);
  transition:
    transform 0.1s ease,
    box-shadow 0.22s ease,
    background-color 0.35s ease,
    border-color 0.35s ease;
}

/* SSE 新稿：略亮的冷白高亮条 + 左边线 */
.card--new {
  background: linear-gradient(
    90deg,
    #e8f1fa 0%,
    var(--card-tint-from) 42%,
    var(--card-tint-mid) 100%
  );
  border-color: rgba(27, 74, 114, 0.22);
  box-shadow: var(--shadow-card), inset 3px 0 0 var(--accent-mark);
}

.card:active {
  transform: scale(0.992);
}

.card:focus-within {
  outline: none;
  border-color: rgba(27, 74, 114, 0.45);
  box-shadow:
    var(--shadow-card),
    0 0 0 2px rgba(255, 255, 255, 0.42),
    0 0 0 5px rgba(27, 74, 114, 0.32);
}

.card--clickable {
  cursor: pointer;
}

@keyframes cardLivePush {
  from {
    opacity: 0;
    transform: translateY(-8px);
    box-shadow:
      0 0 0 1px rgba(147, 197, 253, 0.55),
      0 8px 28px rgba(0, 0, 0, 0.35);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    box-shadow: var(--shadow-card);
  }
}

.card--live-push {
  animation: cardLivePush 0.42s ease-out both;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.22rem 0.45rem;
  margin-bottom: 0.22rem;
  padding-bottom: 0.42rem;
  border-bottom: 1px solid var(--card-divider);
}

.card-title {
  flex: 1;
  min-width: 10rem;
  margin: 0;
  font-size: 0.90625rem;
  font-weight: 650;
  line-height: 1.35;
  color: var(--card-title-fg);
  letter-spacing: 0.015em;
}

@supports not (font-weight: 650) {
  .card-title {
    font-weight: 600;
  }
}

.date {
  width: 100%;
  font-size: 0.6875rem;
  color: var(--card-meta-fg);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  font-weight: 500;
}

.summary {
  margin: 0.28rem 0 0;
  font-size: 0.8125rem;
  color: var(--card-secondary-fg);
  font-weight: 500;
  line-height: 1.55;
}

.stocks {
  margin-top: 0.45rem;
  padding-top: 0.42rem;
  border-top: 1px solid var(--card-divider);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

@media (any-hover: hover) {
  /* 任意具备悬停能力的输入（如鼠标）；避免单独依赖 pointer:fine——窄窗口 / 触控本 / DevTools 设备模式常为 coarse，会导致整段折叠规则不匹配 */
  /* 指针设备：默认收起 AI 分析区，悬停卡片时再展开；移开后隐藏 */
  .card--clickable .stocks--has-rows {
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    gap: 0;
    overflow: hidden;
    pointer-events: none;
    transition:
      opacity 0.2s ease,
      visibility 0.2s ease,
      max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
      margin-top 0.2s ease,
      padding-top 0.2s ease,
      gap 0.2s ease;
  }

  .card--clickable:hover .stocks--has-rows {
    opacity: 1;
    visibility: visible;
    max-height: 400vh;
    margin-top: 0.45rem;
    padding-top: 0.42rem;
    border-top: 1px solid var(--card-divider);
    gap: 0.35rem;
    overflow: visible;
    pointer-events: auto;
  }
}

@media (any-hover: hover) and (prefers-reduced-motion: reduce) {
  .card--clickable .stocks--has-rows {
    opacity: 1;
    visibility: visible;
    max-height: none;
    margin-top: 0.45rem;
    padding-top: 0.42rem;
    border-top: 1px solid var(--card-divider);
    gap: 0.35rem;
    overflow: visible;
    pointer-events: auto;
    transition: none;
  }
}

/* 大屏不展示「AI 分析」点按按钮（用悬停展开） */
@media (min-width: 821px) {
  .stockpeek-btn {
    display: none !important;
  }
}

/* 窄屏 + 系统判定无悬停（多数手机）：折叠个股区，用「AI 分析」按钮展开/收起 */
.stockpeek-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  width: fit-content;
  margin: 0.28rem 0 0;
  padding: 0.32rem 0.62rem;
  border: 1px solid rgba(27, 74, 114, 0.28);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(248, 252, 255, 0.98), rgba(236, 244, 252, 0.95));
  color: var(--accent-mark);
  font-family: inherit;
  font-size: 0.703125rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.stockpeek-btn:active {
  opacity: 0.88;
}

@media (max-width: 820px) and (hover: none) {
  .stockpeek-btn {
    display: inline-flex;
  }

  .card--clickable .stocks--has-rows {
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    gap: 0;
    overflow: hidden;
    pointer-events: none;
    transition:
      opacity 0.2s ease,
      visibility 0.2s ease,
      max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
      margin-top 0.2s ease,
      padding-top 0.2s ease,
      gap 0.2s ease;
  }

  /* 触控后偶发残留的 :hover 不展开正文下的股票列表 */
  .card--clickable:hover .stocks--has-rows {
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    gap: 0;
    overflow: hidden;
    pointer-events: none;
  }

  .card--clickable.card--stockpeek-open .stocks--has-rows {
    opacity: 1;
    visibility: visible;
    max-height: 400vh;
    margin-top: 0.45rem;
    padding-top: 0.42rem;
    border-top: 1px solid var(--card-divider);
    gap: 0.35rem;
    overflow: visible;
    pointer-events: auto;
  }
}

.stock-line {
  font-size: 0.8125rem;
}

.stock-line .row-main {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.33rem;
  align-items: baseline;
}

.stock-line .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--card-code-fg);
  font-size: 0.75rem;
  font-weight: 600;
}

.stock-line .name {
  font-weight: 700;
  color: var(--card-title-fg);
}

.stock-line .dir {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.stock-line .dir.up {
  color: #921515;
}

.stock-line .dir.down {
  color: #145218;
}

.stock-line .dir.neutral {
  color: var(--card-meta-fg);
  font-weight: 600;
}

.stock-line .reason {
  margin: 0.1rem 0 0;
  padding-left: 0;
  font-size: 0.75rem;
  color: var(--card-meta-fg);
  line-height: 1.48;
  min-height: 1.48em;
}

.stock-line .reason.reason-typewriting::after,
.detail-reason.reason-typewriting::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  vertical-align: -0.12em;
  margin-left: 2px;
  background: var(--card-meta-fg);
  animation: reasonCaretBlink 0.9s steps(1, end) infinite;
}

@keyframes reasonCaretBlink {
  0%,
  45% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.next-day {
  margin: 0.2rem 0 0;
  padding-left: 0;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.42;
}

.next-day.up {
  color: #921515;
  font-weight: 700;
}

.next-day.down {
  color: #145218;
  font-weight: 700;
}

.next-day.flat {
  color: var(--card-meta-fg);
  font-weight: 600;
}

.next-day.muted {
  color: var(--card-meta-fg);
  font-weight: 500;
}

.next-day-date {
  font-weight: 500;
  color: var(--card-meta-fg);
  font-size: 0.6875rem;
}

.sentinel {
  height: 1px;
  margin: 0.45rem 0;
}

.end {
  text-align: center;
  font-size: 0.78125rem;
  margin: 0.38rem 0 0;
}

.loading {
  text-align: center;
  padding: 0.9rem 0.6rem;
  font-size: 0.8125rem;
  line-height: 1.5;
}

body.detail-open {
  overflow: hidden;
  touch-action: none;
}

.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.detail-modal[hidden] {
  display: none;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.48);
}

.detail-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 42rem;
  max-height: min(92dvh, 900px);
  margin: 0;
  padding: 1rem 1rem 1.1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1.1rem, env(safe-area-inset-bottom));
  background: var(--wx-surface);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  border: 1px solid var(--wx-border);
  border-bottom: none;
  box-shadow:
    0 -8px 32px rgba(15, 23, 42, 0.14),
    0 -1px 0 rgba(255, 255, 255, 0.06) inset;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  color-scheme: light;
}

@media (min-width: 821px) {
  .detail-modal {
    align-items: flex-start;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .detail-backdrop {
    backdrop-filter: blur(2px);
  }

  .detail-panel {
    width: min(42rem, 100%);
    max-height: min(88vh, 900px);
    margin-top: 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--wx-border);
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.16);
  }
}

.detail-close {
  position: absolute;
  top: max(0.5rem, env(safe-area-inset-top));
  right: 0.65rem;
  width: 44px;
  height: 44px;
  border: 1px solid var(--wx-border-soft);
  border-radius: 6px;
  background: var(--wx-bg-page);
  color: var(--wx-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.detail-close:active {
  opacity: 0.65;
}

.detail-heading {
  margin: 0 3rem 0.45rem 0;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--wx-border-light);
  font-size: 1.0625rem;
  font-weight: 650;
  line-height: 1.42;
  color: var(--wx-text);
  letter-spacing: 0.02em;
}

@supports not (font-weight: 650) {
  .detail-heading {
    font-weight: 600;
  }
}

.detail-meta {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--wx-muted);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.detail-summary {
  margin: 0 0 0.65rem;
  font-size: 0.875rem;
  color: var(--wx-text-secondary);
  line-height: 1.65;
}

.detail-subh {
  margin: 0.8rem 0 0.35rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-mark);
}

.detail-subh:first-of-type {
  margin-top: 0.2rem;
}

.detail-pre-wrap {
  margin: 0;
  padding: 0.8rem 0.95rem;
  font-size: 0.921875rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
  border: 1px solid var(--wx-border-soft);
  border-radius: 6px;
  color: var(--wx-text);
  max-height: min(42vh, 400px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 821px) {
  .detail-pre-wrap {
    max-height: min(38vh, 360px);
  }
}

.detail-stocks {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.detail-stock-card {
  padding: 0.72rem 0.85rem;
  background: linear-gradient(180deg, var(--wx-surface) 0%, #fafbfd 100%);
  border: 1px solid var(--wx-border-soft);
  border-radius: 6px;
  border-left: 3px solid rgba(27, 74, 114, 0.35);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.detail-stock-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.45rem;
  align-items: baseline;
  font-size: 0.875rem;
}

.detail-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--code);
  font-size: 0.8125rem;
}

.detail-name {
  font-weight: 600;
}

.detail-reason {
  margin: 0.3rem 0 0;
  font-size: 0.8125rem;
  color: var(--wx-muted);
  line-height: 1.6;
  min-height: 1.6em;
}

.detail-muted {
  margin: 0;
  font-size: 0.875rem;
  color: var(--wx-muted);
}

/* 手机 / 窄屏：排版、触控与微信内置浏览器 */
@media (max-width: 820px) {
  .pane-scroll {
    padding: 0.45rem 0.52rem 0.72rem;
    padding-left: max(0.52rem, env(safe-area-inset-left));
    padding-right: max(0.52rem, env(safe-area-inset-right));
    padding-top: max(0.45rem, env(safe-area-inset-top));
    padding-bottom: max(0.72rem, calc(0.45rem + env(safe-area-inset-bottom)));
  }

  .news-list {
    gap: 0.48rem;
  }

  .card {
    padding: 0.6rem 0.65rem;
    border-radius: var(--radius);
  }

  .card-title {
    min-width: 0;
    font-size: 0.921875rem;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.32;
  }

  .date {
    font-size: 0.703125rem;
    word-break: break-word;
  }

  .summary,
  .stock-line {
    font-size: 0.828125rem;
  }

  .stock-line .reason {
    font-size: 0.765625rem;
  }

  .next-day {
    font-size: 0.765625rem;
  }

  .detail-panel {
    max-height: min(90dvh, 100dvh);
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding-left: max(0.85rem, env(safe-area-inset-left));
    padding-right: max(0.85rem, env(safe-area-inset-right));
  }

  .detail-heading {
    font-size: 1.0625rem;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .detail-pre-wrap {
    max-height: min(48dvh, 60vh);
    font-size: 1rem;
    line-height: 1.75;
  }

  .btn,
  .card--clickable {
    touch-action: manipulation;
  }
}

@media (min-width: 821px) {
  body {
    height: 100vh;
    height: 100dvh;
  }

  .card:hover {
    border-color: rgba(15, 23, 42, 0.14);
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.2),
      0 4px 16px rgba(0, 0, 0, 0.22),
      0 20px 48px rgba(0, 0, 0, 0.32);
  }

  .card.card--new:hover {
    border-color: rgba(27, 74, 114, 0.32);
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.2),
      0 4px 16px rgba(0, 0, 0, 0.22),
      0 20px 48px rgba(0, 0, 0, 0.32),
      inset 3px 0 0 var(--accent-mark);
  }

  .btn:hover {
    background: var(--wx-bg-page);
    border-color: #b8c3d4;
  }

  .btn-primary:hover {
    background: var(--wx-green-press);
    border-color: var(--wx-green-press);
    color: #fff;
  }

  .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
  }

  .detail-close:hover {
    background: var(--wx-border-soft);
    color: var(--wx-text);
  }
}
