/* Shared reading theme. Admin pages intentionally use their own stylesheet. */
:root {
  --ink-rgb: 17, 17, 20;
  --muted: #6a6862;
  --edge: #111114;
  --surface: #fff;
  --focus: #b32600;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #111114;
  --paper-dim: #1c1c21;
  --ink: #f4f1e9;
  --ink-rgb: 244, 241, 233;
  --muted: #b3b0a8;
  --edge: #56565d;
  --surface: #1b1b20;
  --heat: #ff633f;
  --mint: #3bffc9;
  --focus: #3bffc9;
  --rule: 3px solid var(--edge);
  --rule-thin: 2px solid var(--edge);
  color-scheme: dark;
}

/* These panels stay ink-on-paper inverted in BOTH themes. */
:is(.hero, .proof, .ticker, .agent-code-box, .login-intro, .story:hover) {
  --ink: #111114;
  --paper: #f4f1e9;
  --ink-rgb: 17, 17, 20;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
  min-height: 36px;
  margin: 0;
  padding: 7px 11px;
  border: 1px solid var(--edge);
  border-radius: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-display, var(--display, sans-serif));
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}
.theme-toggle:hover { background: var(--paper-dim); border-color: var(--heat); }
.theme-toggle .theme-sun { display: none; }
[data-theme="dark"] .theme-toggle .theme-sun { display: block; }
[data-theme="dark"] .theme-toggle .theme-moon { display: none; }
.theme-toggle svg { flex: 0 0 18px; }
:is(.theme-toggle, .story-btn, .sb-admin-btn, .sb-session-btn, .event-action, .original-toggle summary):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
.story:has(:focus-visible) { outline: 2px solid var(--focus); outline-offset: 5px; }
.header-title-box { min-width: 0; }
.topbar-header-row { align-items: center; }
.header-date-subtitle { overflow-wrap: anywhere; }
.topbar-right-controls { flex-wrap: wrap; min-width: 0; }
.search-box { min-width: 0; width: min(100%, 340px); }
.search-box:focus-within { background: var(--surface); }
.search-box:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.search-input { min-width: 0; }
#wechatAuthorFilters .btn-seg {
  padding: 6px 10px;
  border: 1px solid var(--edge);
  border-radius: 0;
  color: var(--ink);
  background: var(--paper);
  font: inherit;
  font-size: 12px;
  min-height: 36px;
  cursor: pointer;
}
#wechatAuthorFilters .btn-seg.active {
  color: #111114;
  background: var(--mint);
  border-color: #111114;
  font-weight: 700;
}
#wechatAuthorFilters .btn-seg:hover { border-color: var(--heat); }
#wechatAuthorFilters .btn-seg:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.counter-pill { white-space: normal; }
.story-main { min-width: 0; }
.s-actions-row { flex-wrap: wrap; }
.topic-modal-overlay { background: rgba(0, 0, 0, .72); }
.reader-drawer-overlay { background: rgba(0, 0, 0, .65); }
.reader-drawer { box-shadow: -10px 0 30px rgba(0, 0, 0, .25); }
:is(.topic-modal-body, .reader-drawer) { overscroll-behavior: contain; }
.topic-card-chip, .hot-entity-card, .benchmark-table-wrap, .agent-endpoint-card,
.drawer-summary-box, .drawer-why-box, .drawer-source-item { background: var(--surface); }

/* Avoid white cards, low-contrast mint labels and inverted-white hover flashes. */
[data-theme="dark"] :is(.sb-nav-item.active, .sb-admin-btn, .sb-session-btn:hover,
  .brand-cn-tag, .score-seg .btn-seg.active, nav.primary .mast-back, nav.primary a:hover,
  .mast-session-link:hover, .event-action, .event-page .s-kicker .cat,
  .drawer-close-btn, .topic-modal-close, .digest-read-btn) {
  color: #f4f1e9;
  background: #25252b;
  border-color: var(--edge);
}
[data-theme="dark"] .sb-nav-item.active {
  box-shadow: inset 3px 0 0 var(--mint);
  color: var(--mint);
}
[data-theme="dark"] .sb-nav-item:hover:not(.active) {
  background: #25252b;
  color: #f4f1e9;
}
[data-theme="dark"] :is(.sb-badge, .sb-section-title, .search-box, .search-key,
  .score-seg .btn-seg, nav.primary a, .mast-session-link, .sb-session-btn,
  .topic-modal-window, .topic-modal-head, .topic-col-title, .topic-card-chip,
  .hot-entity-card, .benchmark-table-wrap, .benchmark-table th, .benchmark-table td,
  .agent-endpoint-card, .drawer-section-title, .drawer-summary-box, .drawer-source-item,
  .original-toggle summary, .s-proof) { border-color: var(--edge); }
[data-theme="dark"] .sb-nav-item.active .sb-badge,
[data-theme="dark"] .feed-load-sentinel button,
[data-theme="dark"] .original-toggle summary:hover {
  background: var(--mint);
  color: #111114;
  border-color: var(--mint);
}
[data-theme="dark"] .story {
  background: #111114;
  color: #f4f1e9;
}
[data-theme="dark"] .story:hover {
  background: #19191e;
  box-shadow: 32px 0 0 #19191e, -32px 0 0 #19191e;
}
[data-theme="dark"] .story .rank { -webkit-text-stroke: 0; color: var(--heat); }
[data-theme="dark"] .story .s-src .n { color: var(--mint); }
[data-theme="dark"] .story .tags i { color: var(--mint); }
[data-theme="dark"] :is(.topic-card-chip:hover, .hot-entity-card:hover, .drawer-source-item:hover) {
  background: #25252b;
  color: #f4f1e9;
}
[data-theme="dark"] :is(.topic-modal-window, .hot-entity-card, .benchmark-table-wrap, .agent-endpoint-card) {
  box-shadow: 4px 4px 0 #070709;
}
[data-theme="dark"] .story-btn:hover,
[data-theme="dark"] .story-btn.is-starred { color: #111114; }
[data-theme="dark"] .event-page .why { background: rgba(255, 99, 63, .08); }
[data-theme="dark"] .event-next-list li { border-bottom-color: var(--edge); }
[data-theme="dark"] .event-action:hover { border-color: var(--mint); color: var(--mint); }
[data-theme="dark"] :is(.coverage-item .ttl a:hover, .digest-item h3 a:hover) {
  color: #f4f1e9;
  background: #25252b;
}
[data-theme="dark"] :is(.score-seg .btn-seg, .sb-admin-btn, .drawer-close-btn, .topic-modal-close):hover {
  background: #34343b;
  color: #f4f1e9;
}
[data-theme="dark"] :is(.site-sidebar, .reader-drawer, .topic-modal-body) {
  scrollbar-color: #68686f #1c1c21;
}
[data-theme="dark"] .site-sidebar::-webkit-scrollbar-thumb { background: #68686f; }
[data-theme="dark"] select { color: var(--ink); background: var(--surface); }
[data-theme="dark"] .login-panel input { background: var(--surface); border-color: var(--edge); }
[data-theme="dark"] .login-panel button { background: var(--mint); color: #111114; border-color: var(--mint); }
[data-theme="dark"] .login-panel button:hover { background: #84ffdf; }
[data-theme="dark"] .form-message.error { color: #ff947b; }
[data-theme="dark"] .form-message.success { color: var(--mint); }
.login-masthead .masthead-channel { margin-left: auto; }

@media (max-width: 768px) {
  .topbar-header-row { flex-direction: row; align-items: flex-start; gap: 12px; }
  .header-title-box h1 { font-size: 21px; }
  .content-topbar { position: relative; top: auto; padding: 16px; }
  .day-sticky-title { position: relative; top: auto; gap: 12px; flex-wrap: wrap; }
  .feed-head { align-items: flex-start; gap: 10px; flex-wrap: wrap; }
  .search-box { width: 100%; }
  .theme-toggle { min-height: 40px; }
  .mast-tools .theme-toggle { width: 36px; min-height: 36px; padding: 7px; }
  .mast-tools .theme-toggle [data-theme-label] { display: none; }
  .topbar-right-controls { width: 100%; justify-content: space-between; gap: 10px; }
  .topic-modal-body { grid-template-columns: 1fr; padding: 16px; }
  .topic-modal-head { padding: 14px; gap: 10px; }
  .feed-load-sentinel { flex-wrap: wrap; }
  [data-theme="dark"] .story:hover { box-shadow: none; }
  .s-proof { flex-wrap: wrap; }
}
@media (max-width: 380px) {
  .masthead { grid-template-areas: "brand brand" "nav nav" "tools tools"; }
  .mast-tools { justify-content: flex-start; }
  .mast-tools .theme-toggle { width: auto; padding-inline: 10px; }
  .mast-tools .theme-toggle [data-theme-label] { display: inline; }
  .topbar-header-row { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
