/* =========================================================================
   major.mancy.news — minimalist, reading-first stylesheet
   Light + dark via CSS variables. prefers-color-scheme is the default;
   a manual choice stamps <html data-theme="light|dark"> and always wins.
   ========================================================================= */

/* ---- Design tokens -------------------------------------------------------
   Light is the default :root. Dark comes from BOTH prefers-color-scheme
   (system default) and [data-theme="dark"] (manual override). We also give
   [data-theme="light"] an explicit block so a user on a dark system who
   picks "light" is honoured. */

:root {
  --bg:        #fbfbfa;
  --surface:   #ffffff;
  --surface-2: #f4f4f2;
  --text:      #1a1a1a;
  --text-soft: #3d3d3d;
  --muted:     #6c6c6c;
  --border:    #e5e4e1;
  --border-strong: #d5d4d0;
  --accent:    #b02418;
  --accent-soft: #f6e4e1;
  --link:      #b02418;

  --dot-high:  #e5484d;
  --dot-med:   #f5a623;
  --dot-low:   #2fa84f;

  --badge-full-bg:  #eae7ff;
  --badge-full-fg:  #4b3fbf;
  --badge-inc-bg:   #e5f1ff;
  --badge-inc-fg:   #1f6fb2;

  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.04);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK",
             "Noto Sans CJK TC", "Microsoft JhengHei", "Hiragino Sans", sans-serif;
  --font-read: var(--font-ui);

  --read-w: 46rem;
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0f1113;
    --surface:   #16181b;
    --surface-2: #1d2024;
    --text:      #e9e9e6;
    --text-soft: #cfd0cc;
    --muted:     #9aa0a6;
    --border:    #2a2d31;
    --border-strong: #3a3e43;
    --accent:    #ff6f61;
    --accent-soft: #3a201d;
    --link:      #ff8a7e;

    --dot-high:  #ff6b6b;
    --dot-med:   #ffb84d;
    --dot-low:   #4fd06a;

    --badge-full-bg:  #2a2740;
    --badge-full-fg:  #b9b0ff;
    --badge-inc-bg:   #1c2c3a;
    --badge-inc-fg:   #8ec6ff;

    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

/* Manual dark (wins even on a light system). */
:root[data-theme="dark"] {
  --bg:        #0f1113;
  --surface:   #16181b;
  --surface-2: #1d2024;
  --text:      #e9e9e6;
  --text-soft: #cfd0cc;
  --muted:     #9aa0a6;
  --border:    #2a2d31;
  --border-strong: #3a3e43;
  --accent:    #ff6f61;
  --accent-soft: #3a201d;
  --link:      #ff8a7e;

  --dot-high:  #ff6b6b;
  --dot-med:   #ffb84d;
  --dot-low:   #4fd06a;

  --badge-full-bg:  #2a2740;
  --badge-full-fg:  #b9b0ff;
  --badge-inc-bg:   #1c2c3a;
  --badge-inc-fg:   #8ec6ff;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

/* ---- Base ---------------------------------------------------------------- */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.75;
  letter-spacing: .01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden; /* body must never scroll horizontally */
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

strong { font-weight: 700; color: var(--text); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Reading column */
.reading {
  width: 100%;
  max-width: var(--read-w);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: .5rem .9rem;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 50;
}
.skip-link:focus { left: 0; }

/* ---- Header / nav -------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}

.bar {
  max-width: 64rem;
  margin: 0 auto;
  padding: .55rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  color: var(--text);
  font-weight: 700;
}
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 1.35rem; line-height: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-zh { font-size: 1.05rem; letter-spacing: .06em; }
.brand-en {
  font-size: .68rem;
  color: var(--muted);
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 600;
}

.nav {
  display: flex;
  gap: .15rem;
  margin-left: auto;
  flex-wrap: wrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 .7rem;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-weight: 600;
  font-size: .95rem;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.theme-toggle {
  min-width: 40px;
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  padding: 0;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-icon { font-size: 1.1rem; line-height: 1; }
.theme-icon::before { content: "🌙"; }
:root[data-theme="dark"] .theme-icon::before { content: "☀️"; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon::before { content: "☀️"; }
}

/* ---- Generic view scaffolding ------------------------------------------- */

.view-head { margin: .25rem 0 1.75rem; }
.view-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 0 0 .35rem;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 1rem;
}

/* Report header block (shared by Latest + Report) */
.report-head {
  border-bottom: 2px solid var(--border-strong);
  padding-bottom: 1.1rem;
  margin-bottom: 1.75rem;
}
.report-round {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  flex-wrap: wrap;
}
.report-round h1 {
  font-size: 1.7rem;
  line-height: 1.3;
  margin: 0;
  letter-spacing: .01em;
}
.report-meta {
  margin-top: .5rem;
  color: var(--muted);
  font-size: .92rem;
  display: flex;
  gap: .4rem 1rem;
  flex-wrap: wrap;
  align-items: center;
}
.report-meta .dot-sep::before { content: "·"; margin-right: .9rem; color: var(--border-strong); }
.updated { color: var(--accent); font-weight: 600; }
.coverage {
  margin-top: .75rem;
  color: var(--text-soft);
  font-size: .95rem;
  background: var(--surface-2);
  border-left: 3px solid var(--border-strong);
  padding: .55rem .8rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Section headings */
.section { margin: 2.25rem 0; }
.section > h2 {
  font-size: 1.28rem;
  margin: 0 0 1rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.section-emoji { font-size: 1.2rem; }

/* ---- Importance dot ------------------------------------------------------ */

.dot {
  flex: none;
  width: .62rem;
  height: .62rem;
  border-radius: 50%;
  display: inline-block;
  margin-top: .55rem;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}
.dot.imp-high   { background: var(--dot-high); color: var(--dot-high); }
.dot.imp-medium { background: var(--dot-med);  color: var(--dot-med); }
.dot.imp-low    { background: var(--dot-low);  color: var(--dot-low); }

/* ---- TL;DR list ---------------------------------------------------------- */

.tldr-list, .agg-list, .cat-feed { list-style: none; margin: 0; padding: 0; }

.tldr-item {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: .1rem .55rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.tldr-item:last-child { border-bottom: 0; }
.tldr-item > .cat-emoji { margin-top: .3rem; font-size: 1.05rem; }
.tldr-body { min-width: 0; }
.tldr-title {
  font-weight: 700;
  color: var(--text);
  display: block;
}
.tldr-summary {
  color: var(--text-soft);
  font-size: .95rem;
  display: block;
  margin-top: .1rem;
}
.tldr-meta {
  display: block;
  margin-top: .25rem;
  font-size: .8rem;
  color: var(--muted);
}
a.tldr-item { color: inherit; }
a.tldr-item:hover { text-decoration: none; background: var(--surface-2); border-radius: var(--radius-sm); }
a.tldr-item:hover .tldr-title { color: var(--accent); }

/* Clickable TL;DR row (opens the detail modal). Reset native button chrome. */
button.tldr-item {
  width: 100%;
  font: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: inherit;
  cursor: pointer;
}
button.tldr-item:last-child { border-bottom: 0; }
button.tldr-item:hover { background: var(--surface-2); border-radius: var(--radius-sm); }
button.tldr-item:hover .tldr-title { color: var(--accent); }
.tldr-more {
  display: inline-block;
  margin-top: .3rem;
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
  transition: opacity .12s ease;
}
button.tldr-item:hover .tldr-more,
button.tldr-item:focus-visible .tldr-more { opacity: 1; }
@media (hover: none) { .tldr-more { opacity: .8; } }

/* Important events */
.event {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: .9rem;
  box-shadow: var(--shadow);
}
.event-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .4rem;
}
.event-head .dot { margin-top: 0; }
.event-title { font-weight: 700; font-size: 1.08rem; }
.prose p { margin: 0 0 .7rem; }
.prose p:last-child { margin-bottom: 0; }

/* Category body sections */
.cat-block { margin-bottom: 1.6rem; }
.cat-block > h3 {
  font-size: 1.12rem;
  margin: 0 0 .35rem;
  display: flex;
  align-items: center;
  gap: .45rem;
}
.cat-block .prose { color: var(--text-soft); }

/* ---- Sources ------------------------------------------------------------- */

.sources { margin-top: 1rem; }
.source-group { margin-bottom: 1rem; }
.source-group h4 {
  font-size: .82rem;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 .35rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.source-list { list-style: none; margin: 0; padding: 0; }
.source-list li {
  padding: .28rem 0;
  font-size: .92rem;
  line-height: 1.5;
}
.source-list a::before { content: "↗"; margin-right: .35rem; opacity: .6; font-size: .85em; }

/* ---- Badges & chips ------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: .08rem .5rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.mode-full { background: var(--badge-full-bg); color: var(--badge-full-fg); }
.badge.mode-incremental { background: var(--badge-inc-bg); color: var(--badge-inc-fg); }
.badge.high {
  background: color-mix(in srgb, var(--dot-high) 16%, transparent);
  color: var(--dot-high);
}

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .25rem 0 1.5rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  min-height: 36px;
  padding: 0 .75rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-soft);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}
.chip:hover { background: var(--surface-2); text-decoration: none; }
.chip[aria-current="true"], .chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---- 24h aggregate & timeline ------------------------------------------- */

.agg-cat { margin-bottom: 1.8rem; }
.agg-cat > h3 {
  font-size: 1.14rem;
  margin: 0 0 .5rem;
  display: flex;
  align-items: center;
  gap: .45rem;
  position: sticky;
  top: 3.6rem;
  background: var(--bg);
  padding: .2rem 0;
}
.count-pill {
  margin-left: auto;
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
}

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}
.timeline li:last-child { border-bottom: 0; }
.timeline .tl-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.timeline .tl-round { color: var(--muted); }
.timeline .tl-high { margin-left: auto; color: var(--dot-high); font-weight: 700; font-size: .88rem; }

/* ---- Archive ------------------------------------------------------------- */

.archive-date { margin: 2rem 0 .5rem; }
.archive-date h2 {
  font-size: 1rem;
  color: var(--muted);
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  padding-bottom: .3rem;
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.arc-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .3rem .8rem;
  padding: .8rem 0;
  border-bottom: 1px solid var(--border);
  color: inherit;
  align-items: start;
}
.arc-row:hover { text-decoration: none; background: var(--surface-2); border-radius: var(--radius-sm); }
.arc-row:hover .arc-titles { color: var(--accent); }
.arc-left {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  align-items: flex-start;
}
.arc-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
}
.arc-round { font-size: .8rem; color: var(--muted); }
.arc-badges { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.arc-titles {
  color: var(--text-soft);
  font-size: .95rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  min-width: 0;
}
.arc-titles span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Search -------------------------------------------------------------- */

.search-box {
  display: flex;
  gap: .5rem;
  margin-bottom: .5rem;
}
.search-box input[type="search"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: .6rem .8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.search-box button {
  font: inherit;
  font-weight: 600;
  padding: 0 1rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.search-result {
  display: block;
  padding: .9rem 0;
  border-bottom: 1px solid var(--border);
  color: inherit;
}
.search-result:hover { text-decoration: none; }
.search-result:hover .sr-title { color: var(--accent); }
.sr-title { font-weight: 700; font-size: 1.05rem; }
.sr-meta { color: var(--muted); font-size: .85rem; margin: .1rem 0 .3rem; }
.snippet { color: var(--text-soft); font-size: .93rem; }
.snippet mark {
  background: color-mix(in srgb, var(--dot-med) 45%, transparent);
  color: inherit;
  padding: 0 .1em;
  border-radius: 3px;
}

/* ---- States -------------------------------------------------------------- */

.state {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}
.spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.state.error { color: var(--accent); }
.state button {
  margin-top: 1rem;
  font: inherit;
  font-weight: 600;
  padding: .5rem 1.1rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.empty { color: var(--muted); padding: 1.5rem 0; }

/* ---- Detail modal -------------------------------------------------------- */

body.modal-open { overflow: hidden; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: color-mix(in srgb, #000 55%, transparent);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 1rem 2rem;
  overflow-y: auto;
  animation: fade .15s ease;
}
.modal {
  position: relative;
  width: 100%;
  max-width: 40rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.6rem 1.5rem 1.85rem;
  animation: pop .16s ease;
}
.modal:focus { outline: none; }
.modal-close {
  position: absolute;
  top: .45rem;
  right: .45rem;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  line-height: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-kicker {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: .5rem;
}
.modal-kicker .dot { margin-top: 0; margin-left: .25rem; }
.modal-imp { color: var(--text-soft); }
.modal-title {
  font-size: 1.35rem;
  line-height: 1.35;
  margin: 0 0 .55rem;
  padding-right: 2.25rem;
}
.modal-summary { color: var(--text-soft); font-size: 1rem; margin-bottom: .25rem; }
.modal-section {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.modal-section h3 {
  font-size: .95rem;
  margin: 0 0 .5rem;
  color: var(--muted);
  letter-spacing: .04em;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.modal-section .prose { color: var(--text-soft); font-size: .96rem; }
.modal-section .source-list a::before { content: "↗"; margin-right: .35rem; opacity: .6; font-size: .85em; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Footer -------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .82rem;
}
.site-footer .reading { padding-top: 1.5rem; padding-bottom: 2.5rem; }
.site-footer p { margin: 0; }

/* ---- Small screens ------------------------------------------------------- */

@media (max-width: 560px) {
  body { font-size: 16px; }
  .bar { gap: .5rem .75rem; }
  .brand-en { display: none; }
  .nav { width: 100%; order: 3; margin-left: 0; }
  .theme-toggle { margin-left: auto; }
  .report-round h1 { font-size: 1.4rem; }
  .reading { padding: 1.25rem 1rem 3rem; }
  .agg-cat > h3 { top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; }
}
