/* AI Weekly Digest — editorial UI layer */
@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Source+Sans+3:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap");

:root {
  --bg: #071018;
  --bg-grad-top: #061018;
  --bg-grad-bottom: #0c1a28;
  --panel: rgba(12, 28, 42, 0.82);
  --panel-solid: #0e2233;
  --text: #eef6fb;
  --muted: #8eacc0;
  --accent: #ff3b4a;
  --accent-soft: rgba(255, 59, 74, 0.16);
  --cyan: #3ecfcf;
  --line: rgba(110, 160, 190, 0.22);
  --chip: rgba(20, 44, 64, 0.9);
  --label: #b8d7ea;
  --body-text: #c9dce8;
  --pop: #ffc857;
  --shadow: rgba(0, 8, 16, 0.45);
  --glow: rgba(62, 207, 207, 0.12);
  --radius: 18px;
  --font-display: "Outfit", "Segoe UI", sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

body.light {
  --bg: #f3f7fb;
  --bg-grad-top: #e8f1f7;
  --bg-grad-bottom: #f7fafc;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --text: #132433;
  --muted: #5d7385;
  --accent: #e11d37;
  --accent-soft: rgba(225, 29, 55, 0.1);
  --cyan: #0f8f8f;
  --line: #d5e2ec;
  --chip: #eef4f8;
  --label: #1f4d66;
  --body-text: #334e60;
  --pop: #b45309;
  --shadow: rgba(18, 40, 60, 0.08);
  --glow: rgba(15, 143, 143, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 520px at 8% -10%, rgba(255, 59, 74, 0.18), transparent 55%),
    radial-gradient(900px 480px at 92% 8%, rgba(62, 207, 207, 0.16), transparent 50%),
    linear-gradient(180deg, var(--bg-grad-top) 0%, var(--bg-grad-bottom) 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  transition: background 0.25s, color 0.25s;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,0.55), transparent 70%);
  z-index: 0;
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}

header {
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 26px 26px 20px;
  margin-bottom: 22px;
  box-shadow: 0 18px 50px var(--shadow), inset 0 1px 0 rgba(255,255,255,0.04);
  overflow: hidden;
  position: relative;
}

header::after {
  content: "";
  position: absolute;
  inset: auto -20% -40% auto;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--glow), transparent 70%);
  pointer-events: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 3vw, 2.15rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--text);
  text-decoration: none;
}

.page-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 8px 24px var(--shadow), 0 0 0 1px var(--line);
}

.sub {
  color: var(--muted);
  margin: 0;
  font-size: 0.98rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.stat {
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 0.86rem;
  color: var(--muted);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--cyan) 45%, var(--line));
}

.tabs, .header-actions, .toc {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tabs { margin: 18px 0 0; }

.tab, .theme-btn, .action-btn, .language-button, .filter-chip, .view-btn {
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.tab:hover, .action-btn:hover, .language-button:hover, .filter-chip:hover, .view-btn:hover {
  border-color: var(--cyan);
  transform: translateY(-1px);
}

.tab.active, .filter-chip.active, .view-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.action-btn.primary {
  background: linear-gradient(135deg, #ff3b4a, #ff6a3d);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 22px rgba(255, 59, 74, 0.28);
}

.digest-toolbar {
  display: grid;
  grid-template-columns: 1.4fr auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

#digest-search {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 16px;
  font: inherit;
  outline: none;
}

#digest-search:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(62, 207, 207, 0.18);
}

.filter-row, .view-toggle {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.section-pulse {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.pulse-card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, color-mix(in srgb, var(--chip) 80%, transparent), var(--chip));
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: transform 0.18s ease, border-color 0.18s;
}

.pulse-card:hover {
  transform: translateY(-2px);
  border-color: var(--cyan);
}

.pulse-card .pulse-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pulse-card .pulse-count {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  margin-top: 2px;
}

.pulse-bar {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 70%, transparent);
  overflow: hidden;
}

.pulse-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--accent));
  transform-origin: left;
  animation: growBar 0.7s ease both;
}

@keyframes growBar {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.panel { display: none; }
.panel.active { display: block; }

.section {
  margin-top: 48px;
  scroll-margin-top: 28px;
}

.section h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--cyan);
  margin: 0 0 12px;
}

.section-note { color: var(--muted); margin: 0 0 14px; font-size: 0.92rem; }
.section-comment {
  position: relative;
  margin: 0 0 22px;
  padding: 6px 0 4px 1.15rem;
  border: 0;
  border-left: 3px solid var(--cyan);
  font-family: var(--font-display);
  font-size: clamp(1.42rem, 3.1vw, 2rem);
  line-height: 1.32;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  max-width: 40rem;
  text-wrap: pretty;
  animation: commentIn 0.55s ease both;
}

.section-comment::before {
  content: "“";
  position: absolute;
  top: -0.42em;
  left: 0.7rem;
  font-size: clamp(3.4rem, 7vw, 4.6rem);
  line-height: 1;
  font-weight: 700;
  color: var(--cyan);
  opacity: 0.22;
  pointer-events: none;
  user-select: none;
}

@keyframes commentIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .section-comment { animation: none; }
}

.divider {
  height: 1px;
  background: linear-gradient(90deg, var(--cyan), var(--accent), transparent 78%);
  margin: 0 0 22px;
  border: 0;
  opacity: 0.85;
}

.stock-section, .card, .sources-section {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px var(--shadow);
}

.stock-section {
  margin: 4px 0 28px;
  padding: 20px;
}

.stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.stock-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 14px;
  color: var(--text);
  text-decoration: none;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: transform 0.18s ease, border-color 0.18s;
}

.stock-card:hover {
  border-color: var(--cyan);
  transform: translateY(-3px);
}

.stock-sparkline { grid-column: 1 / -1; width: 100%; height: 40px; margin-top: 4px; }

.card {
  padding: 0;
  margin-bottom: 0;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s, box-shadow 0.2s;
  animation: cardIn 0.45s ease both;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--cyan) 50%, var(--line));
  box-shadow: 0 16px 40px var(--shadow);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.magazine-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.card--feature { grid-column: span 12; }
.card--large { grid-column: span 6; }
.card--compact { grid-column: span 6; }

.card > .meta,
.card-copy {
  padding-left: 18px;
  padding-right: 18px;
}

.card > .meta {
  padding-top: 14px;
  margin-bottom: 8px;
  order: 1;
}

.card .story-image-wrap { order: 2; }

.card-copy {
  order: 3;
  display: flex;
  flex-direction: column;
  padding-bottom: 16px;
}

.card-copy h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.12rem;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.card-copy > p { margin: 6px 0; color: var(--body-text); }
.card-copy > .feedback { margin-top: 10px; padding-top: 0; }

.story-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 280px;
  margin: 0 0 14px;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.card--feature .story-image-wrap {
  aspect-ratio: 21 / 9;
  max-height: 360px;
}

.card--large .story-image-wrap {
  aspect-ratio: 16 / 10;
  max-height: 240px;
}

.card--compact .story-image-wrap {
  aspect-ratio: 16 / 9;
  max-height: 150px;
  margin-bottom: 10px;
}

.card--feature .card-copy h3 {
  font-size: clamp(1.35rem, 2.4vw, 1.75rem);
  letter-spacing: -0.03em;
}

.card--large .card-copy h3 { font-size: 1.22rem; }
.card--compact .card-copy h3 { font-size: 1.05rem; }

.card--compact .article-summary,
.card--compact .article-impact {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card--compact .article-summary { -webkit-line-clamp: 3; }
.card--compact .article-impact { -webkit-line-clamp: 2; }
.card--compact.app-card .card-copy > p:nth-of-type(n+3) { display: none; }

.card--feature {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr);
  grid-template-areas:
    "image meta"
    "image copy";
  gap: 0;
}

.card--feature > .meta {
  grid-area: meta;
  padding: 18px 22px 0;
  margin: 0;
  order: initial;
}

.card--feature .story-image-wrap {
  grid-area: image;
  margin: 0;
  max-height: none;
  min-height: 100%;
  height: 100%;
  aspect-ratio: auto;
  border: 0;
  border-right: 1px solid var(--line);
}

.card--feature .card-copy {
  grid-area: copy;
  padding: 10px 22px 20px;
  order: initial;
}

.story-image, .story-fallback-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 0.45s ease;
}

.story-image { z-index: 2; }
.story-fallback-image { z-index: 1; }

.story-image-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, #26365f, #121933);
}
.story-image-models { background: linear-gradient(135deg, #1d4ed8, #312e81); }
.story-image-agents { background: linear-gradient(135deg, #6d28d9, #1e1b4b); }
.story-image-applications { background: linear-gradient(135deg, #047857, #164e63); }
.story-image-chips { background: linear-gradient(135deg, #b45309, #7c2d12); }
.story-image-china { background: linear-gradient(135deg, #dc2626, #7f1d1d); }
.story-image-policy { background: linear-gradient(135deg, #a16207, #78350f); }
.story-image-research { background: linear-gradient(135deg, #0369a1, #155e75); }

.card:hover .story-image { transform: scale(1.03); }

@media (max-width: 900px) {
  .card--feature,
  .card--large,
  .card--compact {
    grid-column: span 12;
  }

  .card--feature {
    display: flex;
    flex-direction: column;
  }

  .card--feature .story-image-wrap {
    aspect-ratio: 16 / 9;
    max-height: 260px;
    min-height: 0;
    height: auto;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .card--feature > .meta { padding: 14px 18px 0; }
  .card--feature .card-copy { padding: 0 18px 16px; }
}

.pop-meter-wrap {
  margin: 0 0 10px;
}

.pop-meter {
  height: 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 80%, transparent);
  overflow: hidden;
}

.pop-meter > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--pop), var(--accent));
}

.pop-meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.badge {
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
}

.toc-link {
  color: var(--text);
  text-decoration: none;
  font-size: 0.86rem;
  background: var(--chip);
  border: 1px solid var(--line);
  padding: 7px 11px;
  border-radius: 999px;
  transition: border-color 0.15s, background 0.15s;
}

.toc-link:hover, .toc-link.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

body.compact-view .story-image-wrap { display: none; }
body.compact-view .card { padding-bottom: 4px; }
body.compact-view .card--feature {
  display: flex;
  flex-direction: column;
}
body.compact-view .magazine-grid {
  grid-template-columns: 1fr;
  gap: 12px;
}
body.compact-view .card--feature,
body.compact-view .card--large,
body.compact-view .card--compact {
  grid-column: span 1;
}
body.compact-view .card-copy > p:nth-of-type(2) { display: none; }
body.compact-view .card--compact .article-summary,
body.compact-view .card--compact .article-impact {
  -webkit-line-clamp: unset;
  display: block;
}

.card.is-filtered-out { display: none !important; }

.floating-nav {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.floating-nav button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 10px 24px var(--shadow);
}

.floating-nav button:hover { border-color: var(--cyan); }

footer {
  margin-top: 40px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.language-picker { position: relative; }
.language-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  box-shadow: 0 12px 30px var(--shadow);
}

@media (max-width: 820px) {
  .digest-toolbar {
    grid-template-columns: 1fr;
  }
  .floating-nav { right: 12px; bottom: 12px; }
  .wrap { padding: 18px 14px 64px; }
  header { padding: 18px; }
}
