:root {
  --ink: #171514;
  --muted: #746e69;
  --line: #e8e3de;
  --paper: #fff;
  --soft: #f7f5f2;
  --red: #e32922;
  --red-soft: #fff0ed;
  --sidebar: 330px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
body.global-menu-open { overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

.global-nav {
  position: fixed;
  z-index: 90;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: min(390px, 90vw);
  padding: 30px 22px;
  overflow-y: auto;
  background: #fff;
  box-shadow: 20px 0 60px rgba(27, 22, 20, .16);
  transform: translateX(-105%);
  transition: transform .2s ease;
}
.global-nav.is-open { transform: translateX(0); }
.global-nav-brand { display: flex; align-items: center; gap: 12px; margin: 0 8px 24px; font-size: 1.25rem; }
.global-nav-brand img { width: 44px; height: 44px; object-fit: contain; }
.global-nav a {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 13px;
  align-items: center;
  padding: 13px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  text-decoration: none;
}
.global-nav a:hover { background: var(--soft); }
.global-nav a.is-active { border-color: #f5c2bd; background: var(--red-soft); }
.global-nav a > span { display: grid; width: 48px; height: 48px; border-radius: 8px; place-items: center; color: #ac1f19; background: #faf8f6; }
.global-nav a.is-active > span { color: #fff; background: var(--red); }
.global-nav a strong { display: grid; gap: 3px; font-size: .9rem; letter-spacing: .04em; }
.global-nav a small { color: #8d8580; font-size: .72rem; font-weight: 650; letter-spacing: 0; line-height: 1.35; }
.global-scrim {
  position: fixed;
  z-index: 89;
  inset: 0;
  visibility: hidden;
  border: 0;
  opacity: 0;
  background: rgba(22, 19, 17, .38);
  transition: opacity .2s ease, visibility .2s ease;
}
.global-menu-open .global-scrim { visibility: visible; opacity: 1; }

.reader-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.source-sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 28px 20px 20px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #fbfaf9;
}

.reader-shell.is-sidebar-collapsed { --sidebar: 86px; }

.sidebar-head, .reader-brand, .source-row, .group-heading,
.reader-toolbar, .toolbar-links, .article-source-line,
.article-controls, .article-help, .article-next,
.word-actions, .selection-actions, .toolbar-start, .paragraph-actions, .word-links {
  display: flex;
  align-items: center;
}

.sidebar-head { justify-content: space-between; }
.reader-brand {
  gap: 10px;
  font-size: 1.18rem;
  font-weight: 850;
  text-decoration: none;
}
.reader-brand img { width: 42px; height: 42px; object-fit: contain; }
.icon-button, .collapse-button, .group-heading button, .mobile-menu, .back-button,
.panel-close, .selection-close, .modal-close {
  border: 0;
  background: transparent;
}
.collapse-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 1.45rem;
}
.collapse-button:hover { background: #efedeb; }
.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  font-size: 2rem;
  line-height: 1;
}
.icon-button:hover, .group-heading button:hover { background: #efedeb; }
.brand-note {
  margin: 4px 0 34px 52px;
  color: var(--muted);
  font-size: .76rem;
}

.source-nav, .source-list { display: grid; gap: 4px; }
.source-row {
  width: 100%;
  gap: 12px;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  text-align: left;
  background: transparent;
}
.source-row:hover { background: #f0eeeb; }
.source-row.is-active { background: #eee8e6; }
.source-row > span:last-child { display: grid; min-width: 0; }
.source-row strong { font-size: .94rem; }
.script-badge, .article-script-badge {
  display: inline-grid;
  min-width: 24px;
  min-height: 20px;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 4px;
  place-items: center;
  color: #8e332e;
  background: #f8e3df;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: .62rem;
  font-weight: 850;
  vertical-align: middle;
}
.source-row small {
  overflow: hidden;
  color: #99928d;
  font-size: .72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-icon {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  place-items: center;
  color: #746e69;
  background: #ece9e6;
  font-size: .72rem;
  font-weight: 900;
}
.reader-mark { color: #fff; background: var(--red); font-size: 1rem; }
.source-icon.bbc { color: #fff; background: #b80000; }
.source-icon.dw { color: #fff; background: #0873a5; }
.source-icon.rfi { color: #fff; background: #df001b; }
.source-icon.travel { color: #fff; background: #19714c; font-size: 1rem; }
.source-icon.culture { color: #fff; background: #9f3b72; font-size: 1rem; }
.source-icon.podcast { color: #fff; background: #9b3d2f; font-size: 1rem; }
.source-icon.culture-audio { background: #745696; }
.source-icon.video { color: #fff; background: #1f5d76; font-size: 1rem; }
.source-icon.custom { color: #fff; background: #282421; font-size: .9rem; }

.source-group {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.news-group > summary { cursor: pointer; list-style: none; }
.news-group > summary::-webkit-details-marker { display: none; }
.news-group > summary > span { margin: 0 8px 10px 0; color: var(--muted); transition: transform .15s ease; }
.news-group[open] > summary > span { transform: rotate(180deg); }
.group-heading { justify-content: space-between; }
.group-heading p {
  margin: 0 0 10px 10px;
  color: #817a75;
  font-size: .75rem;
  font-weight: 850;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.group-heading button { width: 32px; height: 32px; border-radius: 50%; font-size: 1.1rem; }
.group-note {
  margin: -4px 10px 8px;
  color: #9a938e;
  font-size: .68rem;
  line-height: 1.4;
}
.sidebar-foot {
  display: grid;
  gap: 7px;
  margin-top: auto;
  padding: 22px 10px 0;
  border-top: 1px solid var(--line);
}
.sidebar-foot a {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 750;
  text-decoration: none;
}
.sidebar-foot a:hover { color: var(--red); }

.reader-shell.is-sidebar-collapsed .source-sidebar { padding-inline: 12px; }
.reader-shell.is-sidebar-collapsed .reader-brand span,
.reader-shell.is-sidebar-collapsed .brand-note,
.reader-shell.is-sidebar-collapsed .icon-button,
.reader-shell.is-sidebar-collapsed .source-row > span:last-child,
.reader-shell.is-sidebar-collapsed .group-heading p,
.reader-shell.is-sidebar-collapsed .group-note,
.reader-shell.is-sidebar-collapsed .sidebar-foot {
  display: none;
}
.reader-shell.is-sidebar-collapsed .sidebar-head {
  display: grid;
  justify-content: center;
  gap: 10px;
}
.reader-shell.is-sidebar-collapsed .reader-brand { justify-content: center; }
.reader-shell.is-sidebar-collapsed .source-row { justify-content: center; padding-inline: 0; }
.reader-shell.is-sidebar-collapsed .source-group { margin-top: 18px; padding-top: 14px; }
.reader-shell.is-sidebar-collapsed .group-heading { justify-content: center; }

.reader-main { min-width: 0; }
.reader-toolbar {
  position: sticky;
  z-index: 12;
  top: 0;
  justify-content: space-between;
  min-height: 68px;
  padding: 10px 34px;
  border-bottom: 1px solid rgba(232, 227, 222, .8);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
}
.toolbar-start { gap: 8px; }
.global-menu-button, .mobile-menu {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-weight: 800;
}
.global-menu-button { width: 42px; padding: 0; font-size: 1.1rem; }
.toolbar-brand { display: grid; gap: 2px; font-size: .82rem; font-weight: 900; letter-spacing: .04em; text-align: center; }
.toolbar-brand small { color: #938c87; font-size: .62rem; font-weight: 650; letter-spacing: 0; }
.toolbar-links { gap: 20px; }
.toolbar-links a {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 750;
  text-decoration: none;
}
.toolbar-links a:hover { color: var(--red); }
.mobile-menu { display: none; font-size: 1.2rem; }
.back-button { color: var(--muted); font-weight: 750; }
.back-button:first-letter { color: var(--ink); font-size: 1.6rem; }

.feed-view, .saved-view, .article-view {
  width: min(calc(100% - 64px), 940px);
  margin: 0 auto;
  padding: 62px 0 100px;
}
.view-heading { margin-bottom: 30px; }
.eyebrow {
  margin: 0 0 12px;
  color: #817a75;
  font-size: .76rem;
  font-weight: 900;
  letter-spacing: .09em;
}
.view-heading h1, .article-head h1 {
  max-width: 840px;
  margin: 0;
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-size: clamp(2.1rem, 4.5vw, 4.1rem);
  line-height: 1.08;
  letter-spacing: 0;
}
.view-heading > p:last-child {
  max-width: 680px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
}
.feed-search-wrap { margin-bottom: 22px; }
.feed-search {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}
.feed-search span { color: #8d8681; font-size: 1.3rem; }
.feed-search input {
  width: 100%;
  min-height: 52px;
  border: 0;
  outline: 0;
  background: transparent;
}

.feed-status {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 80px;
  color: var(--muted);
}
.loader {
  width: 20px;
  height: 20px;
  border: 2px solid #ddd7d2;
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.feed-status.is-error {
  padding: 18px;
  border: 1px solid #f3c8c4;
  border-radius: 8px;
  color: #9b211c;
  background: var(--red-soft);
}
.feed-status.is-error .loader { display: none; }

.article-list { border-top: 1px solid var(--line); }
.article-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  width: 100%;
  padding: 23px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  background: transparent;
}
.article-row:hover h2 { color: var(--red); }
.article-row h2 {
  margin: 0 0 8px;
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-size: 1.35rem;
  line-height: 1.4;
}
.article-row p {
  display: -webkit-box;
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.article-row time {
  padding-top: 4px;
  color: #9a938e;
  font-size: .76rem;
  white-space: nowrap;
}
.empty-state {
  padding: 46px 4px;
  color: var(--muted);
}

.article-view { width: min(calc(100% - 64px), 820px); }
.article-source-line { gap: 12px; margin-bottom: 24px; color: #8d8681; font-size: .78rem; }
.article-source-line span { color: var(--red); font-weight: 850; }
.article-row-badge { position: relative; top: -2px; }
.content-type-badge {
  position: relative;
  top: -2px;
  display: inline-grid;
  min-height: 20px;
  margin-left: 5px;
  padding: 0 7px;
  border-radius: 4px;
  place-items: center;
  color: #7a493e;
  background: #f4e8e1;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: .58rem;
  font-weight: 850;
  vertical-align: middle;
}
.content-type-badge.video { color: #24566b; background: #e4f0f5; }
.article-intro {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.7;
}
.article-controls { flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.article-controls button, .article-controls a, .article-next a,
.word-actions button, .selection-actions button, .primary-button {
  min-height: 42px;
  padding: 0 17px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-weight: 780;
  text-decoration: none;
  background: #fff;
}
.article-controls button:hover, .article-controls a:hover,
.article-next a:hover, .word-actions button:hover, .selection-actions button:hover {
  border-color: #f0aaa5;
  color: var(--red);
}
.article-controls button.is-saved { color: #fff; border-color: var(--red); background: var(--red); }
.translation-toggle.is-on { color: #fff; border-color: var(--red); background: var(--red); }
.article-media { margin-top: 24px; }
.media-label {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 800;
}
.article-media audio { display: block; width: 100%; }
.video-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  background: #151515;
}
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.article-help {
  justify-content: space-between;
  gap: 20px;
  margin: 46px 0 28px;
  padding: 14px 18px;
  border-radius: 7px;
  color: #69635f;
  background: var(--soft);
  font-size: .76rem;
}
.article-body {
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-size: 1.22rem;
  line-height: 2;
}
.learning-paragraph {
  margin: 0 0 1.6em;
  padding: 0 0 1.25em;
  border-bottom: 1px solid #f0ece8;
  transition: background .15s ease;
}
.learning-paragraph.is-speaking {
  margin-inline: -14px;
  padding-inline: 14px;
  border-radius: 7px;
  background: #fff6f3;
}
.paragraph-topline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}
.paragraph-chinese { margin: 0; }
.paragraph-actions { gap: 6px; }
.paragraph-listen, .paragraph-translate {
  display: grid;
  width: 34px;
  height: 34px;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 50%;
  place-items: center;
  color: var(--red);
  background: #fff;
  font-size: .68rem;
}
.paragraph-translate { color: #6f6863; font-size: .58rem; font-weight: 850; }
.paragraph-listen:hover, .paragraph-translate:hover { border-color: #f0aaa5; background: var(--red-soft); }
.paragraph-translation {
  margin: 8px 46px 0 0;
  color: #746e69;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: .88rem;
  line-height: 1.6;
}
.paragraph-translation.is-loading { color: #aaa39e; font-style: italic; }
.translations-off .paragraph-translation { display: none; }
.translations-off .learning-paragraph.force-translation .paragraph-translation { display: block; }
.translate-rest {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  font-weight: 800;
  background: #fff;
}
.translate-rest:hover { color: #fff; background: var(--ink); }
.han-char {
  border-radius: 3px;
  cursor: pointer;
  transition: background .12s ease;
}
.han-char:hover { background: #ffddd8; }
.article-next {
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 56px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}
.article-next p { width: 100%; margin: 0 0 7px; color: var(--muted); }

.word-panel {
  position: fixed;
  z-index: 50;
  right: 22px;
  bottom: 22px;
  width: min(390px, calc(100vw - 44px));
  padding: 26px;
  border: 1px solid #f1c1bd;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(45, 29, 24, .18);
}
.panel-close, .selection-close, .modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  font-size: 1.3rem;
}
.word-panel h2 { margin: 0; color: var(--red); font-size: 2.2rem; }
.word-pinyin { margin: 5px 0 16px; font-weight: 800; }
.word-script-note { margin: -2px 0 7px; color: #8a322d; font-size: .78rem; font-weight: 750; }
.word-definitions { color: var(--muted); line-height: 1.55; }
.word-definitions p { margin: 7px 0; }
.word-actions { gap: 8px; margin: 20px 0 15px; }
.word-actions button:last-child { color: #fff; border-color: var(--ink); background: var(--ink); }
.word-actions button:last-child.is-saved { border-color: var(--red); background: var(--red); }
.word-links { flex-wrap: wrap; gap: 12px; }
.word-links a { color: var(--red); font-size: .8rem; font-weight: 750; }

.selection-tools {
  position: fixed;
  z-index: 48;
  left: 50%;
  bottom: 22px;
  width: min(560px, calc(100vw - 44px));
  padding: 18px 50px 18px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #201d1b;
  box-shadow: 0 20px 60px rgba(28, 22, 20, .25);
  color: #fff;
  transform: translateX(-50%);
}
.selection-tools > p:first-of-type {
  overflow: hidden;
  margin: 0 0 12px;
  font-family: Georgia, "Songti SC", "STSong", serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.selection-actions { gap: 8px; }
.selection-actions button { min-height: 36px; color: #fff; border-color: #5b5551; background: transparent; }
.selection-close { color: #fff; }
.selection-translation {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid #48423e;
  color: #eee8e4;
  line-height: 1.5;
}

.modal-backdrop, .mobile-backdrop {
  position: fixed;
  z-index: 60;
  inset: 0;
  background: rgba(25, 21, 19, .42);
}
.source-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(520px, calc(100vw - 36px));
  padding: 32px;
  border-radius: 10px;
  background: #fff;
  transform: translate(-50%, -50%);
}
.source-modal h2 { margin: 0; font-size: 1.8rem; }
.source-modal > p:not(.eyebrow):not(.modal-status) { color: var(--muted); line-height: 1.55; }
.source-modal label { display: grid; gap: 7px; margin-top: 18px; font-size: .8rem; font-weight: 800; }
.source-modal input {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.primary-button { margin-top: 20px; color: #fff; border-color: var(--red); background: var(--red); }
.modal-status { min-height: 22px; margin: 14px 0 0; color: #a3231e; font-size: .82rem; }

@media (max-width: 820px) {
  .reader-shell { display: block; }
  .source-sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-105%);
    width: min(340px, 88vw);
    transition: transform .2s ease;
  }
  .source-sidebar.is-open { transform: translateX(0); }
  .collapse-button { display: none; }
  .reader-shell.is-sidebar-collapsed { --sidebar: 330px; }
  .reader-shell.is-sidebar-collapsed .source-sidebar { padding: 28px 20px 20px; }
  .reader-shell.is-sidebar-collapsed .reader-brand span,
  .reader-shell.is-sidebar-collapsed .brand-note,
  .reader-shell.is-sidebar-collapsed .icon-button,
  .reader-shell.is-sidebar-collapsed .source-row > span:last-child,
  .reader-shell.is-sidebar-collapsed .group-heading p,
  .reader-shell.is-sidebar-collapsed .group-note,
  .reader-shell.is-sidebar-collapsed .sidebar-foot { display: initial; }
  .reader-shell.is-sidebar-collapsed .sidebar-head { display: flex; justify-content: space-between; }
  .reader-shell.is-sidebar-collapsed .source-row { justify-content: flex-start; padding: 10px; }
  .reader-shell.is-sidebar-collapsed .source-group { margin-top: 26px; padding-top: 20px; }
  .reader-shell.is-sidebar-collapsed .group-heading { justify-content: space-between; }
  .reader-shell.is-sidebar-collapsed .source-row > span:last-child { display: grid; }
  .reader-shell.is-sidebar-collapsed .brand-note,
  .reader-shell.is-sidebar-collapsed .group-note { display: block; }
  .reader-shell.is-sidebar-collapsed .icon-button { display: grid; }
  .reader-shell.is-sidebar-collapsed .sidebar-foot { display: grid; }
  .mobile-backdrop { z-index: 18; }
  .mobile-menu { display: block; }
  .reader-toolbar { padding: 9px 16px; }
  .toolbar-brand { display: none; }
  .toolbar-links { gap: 12px; }
  .feed-view, .saved-view, .article-view {
    width: min(calc(100% - 32px), 820px);
    padding-top: 38px;
  }
  .view-heading h1, .article-head h1 { font-size: clamp(2rem, 10vw, 3.2rem); }
  .article-row { grid-template-columns: 1fr; gap: 8px; padding: 20px 0; }
  .article-row time { grid-row: 1; }
  .article-help { display: grid; }
  .article-body { font-size: 1.12rem; }
}

@media (max-width: 520px) {
  .toolbar-links a:first-child { display: none; }
  .feed-view, .saved-view, .article-view { width: calc(100% - 28px); }
  .article-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .article-controls a { display: grid; place-items: center; }
  .article-controls #originalArticleLink { grid-column: 1 / -1; }
  .toolbar-brand { display: none; }
  .word-panel { right: 10px; bottom: 10px; width: calc(100vw - 20px); }
  .selection-tools { bottom: 10px; width: calc(100vw - 20px); }
}
