/* ===== 环视新闻 PWA · iOS 13 Safari compatible =====
   iOS 13 constraints honoured:
   - No flexbox `gap` (Safari 14.1+). Use margins or CSS grid `gap`.
   - No `aspect-ratio`, `inset` shorthand, `:is()`/`:where()`, logical properties.
   - safe-area insets via env() (iOS 11.2+); prefers-color-scheme (Safari 12.1+) OK.
   - Animations use transform/opacity only (no View Transitions API).
*/

/* ---------- Dark (default) ---------- */
:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev2: #1f232c;
  --border: #2a2f3a;
  --header-bg: rgba(15, 17, 21, 0.9);
  --text: #e8eaed;
  --text-dim: #9aa0ac;
  --text-faint: #6b7280;
  --accent: #5b9aff;
  --accent-soft: rgba(91, 154, 255, 0.16);
  --china: #ff6b6b;
  --australia: #ffce5a;
  --global: #4ecb8d;
  --callout-bg: rgba(91, 154, 255, 0.08);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Light (follows device) ---------- */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --bg-elev: #ffffff;
    --bg-elev2: #e9edf3;
    --border: #e1e6ee;
    --header-bg: rgba(244, 246, 249, 0.88);
    --text: #1a1d24;
    --text-dim: #59616e;
    --text-faint: #8b919e;
    --accent: #2f6fe0;
    --accent-soft: rgba(47, 111, 224, 0.10);
    --china: #d6403f;
    --australia: #a9740a;
    --global: #1f9d57;
    --callout-bg: rgba(47, 111, 224, 0.06);
    --shadow: 0 6px 24px rgba(20, 30, 60, 0.12);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }

/* ---------- Header ---------- */
.app-header {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.app-header__bar {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 6px 10px;
}
.app-header__titlewrap {
  flex: 1 1 auto;
  text-align: center;
  overflow: hidden;
  padding: 0 6px;
}
.app-header__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header__sub {
  margin-top: 1px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.iconbtn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  border-radius: 10px;
  cursor: pointer;
  -webkit-transition: background 0.15s ease, -webkit-transform 0.1s ease;
  transition: background 0.15s ease, transform 0.1s ease;
}
.iconbtn:active { background: var(--bg-elev2); -webkit-transform: scale(0.92); transform: scale(0.92); }
.iconbtn--back span { font-size: 30px; font-weight: 600; }
.iconbtn--refresh.is-spinning span {
  display: inline-block;
  -webkit-animation: spin 0.7s linear infinite;
  animation: spin 0.7s linear infinite;
}
.iconbtn--share {
  display: -webkit-box;
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: center;
  justify-content: center;
}
.iconbtn--share svg { width: 20px; height: 20px; }
.iconbtn[hidden] { display: none; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 10px 10px;
  white-space: nowrap;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  margin-right: 8px;
  padding: 7px 16px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, -webkit-transform 0.1s ease;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.1s ease;
}
.tab:last-child { margin-right: 0; }
.tab:active { -webkit-transform: scale(0.95); transform: scale(0.95); }
.tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.tabs[hidden] { display: none; }

/* ---------- Content ---------- */
.content {
  flex: 1 1 auto;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px 28px;
}

/* ---------- States ---------- */
.state { text-align: center; color: var(--text-dim); padding: 64px 16px; }
.state--error { color: var(--china); }
.spinner {
  width: 30px; height: 30px;
  margin: 0 auto 14px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  -webkit-animation: spin 0.8s linear infinite;
  animation: spin 0.8s linear infinite;
}
@-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  display: inline-block;
  margin-top: 14px;
  padding: 9px 20px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Region group heading (list view) ---------- */
.group { margin-bottom: 22px; }
.group__head { display: flex; align-items: center; margin: 6px 2px 12px; }
.group__dot { width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; flex: 0 0 auto; }
.group__title { font-size: 17px; font-weight: 700; margin: 0; }
.group__count { margin-left: 8px; font-size: 12px; color: var(--text-faint); }
.dot-china { background: var(--china); }
.dot-australia { background: var(--australia); }
.dot-global { background: var(--global); }

/* ---------- Story card (list item) ---------- */
.card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  color: var(--text);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: var(--shadow);
  -webkit-animation: cardIn 0.34s ease both;
  animation: cardIn 0.34s ease both;
  -webkit-transition: -webkit-transform 0.12s ease;
  transition: transform 0.12s ease;
}
.card:active { -webkit-transform: scale(0.985); transform: scale(0.985); }
.card__top { display: flex; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  margin-right: 8px;
  flex: 0 0 auto;
}
.badge-china { background: rgba(214, 64, 63, 0.14); color: var(--china); }
.badge-australia { background: rgba(169, 116, 10, 0.16); color: var(--australia); }
.badge-global { background: rgba(31, 157, 87, 0.14); color: var(--global); }
.card__cat { font-size: 12px; color: var(--text-faint); }
.card__title { margin: 0 0 6px; font-size: 17px; font-weight: 700; line-height: 1.4; }
.card__summary {
  margin: 0;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__meta { display: flex; align-items: center; margin-top: 10px; font-size: 12px; color: var(--text-faint); }
.card__sources {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-elev2);
  border-radius: 6px;
  color: var(--text-dim);
  font-weight: 600;
  margin-right: 8px;
}
.card__read {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent-soft);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 600;
}
.card__chev { margin-left: auto; color: var(--text-faint); font-size: 18px; }

/* ---------- Detail view ---------- */
.detail { padding-top: 4px; }
.detail__badges { margin-bottom: 12px; }
.detail__title { font-size: 23px; line-height: 1.35; font-weight: 800; margin: 0 0 12px; }
.detail__lede {
  font-size: 16.5px;
  line-height: 1.75;
  color: var(--text);
  margin: 0 0 14px;
  font-weight: 500;
}
.detail__updated { font-size: 12px; color: var(--text-faint); margin: 18px 0 4px; }

.tags { margin: 0 0 16px; }
.tag-chip {
  display: inline-block;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elev2);
  border-radius: 6px;
  padding: 3px 9px;
  margin: 0 6px 6px 0;
}

.section-label {
  display: flex;
  align-items: center;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.3px;
  margin: 24px 2px 12px;
}
.section-label::before {
  content: "";
  width: 4px; height: 16px;
  background: var(--accent);
  border-radius: 3px;
  margin-right: 8px;
}

.prose { font-size: 15.5px; line-height: 1.8; color: var(--text); margin: 0 2px; }
.prose + .prose { margin-top: 12px; }

/* full-length article (详细报道) — comfortable long-read typography */
.article { margin: 0 2px; }
.article__p {
  font-size: 16.5px;
  line-height: 1.95;
  color: var(--text);
  margin: 0 0 16px;
  text-indent: 2em;
}
.article__p:last-child { margin-bottom: 4px; }
.article__lead {
  text-indent: 0;
  font-weight: 600;
}

/* key facts list */
.facts { list-style: none; margin: 0 0 4px; padding: 0; }
.facts li {
  position: relative;
  padding: 0 0 0 20px;
  margin-bottom: 10px;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}
.facts li::before {
  content: "";
  position: absolute;
  left: 2px; top: 10px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

/* perspective card */
.persp {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 13px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.persp__head { display: flex; align-items: baseline; margin-bottom: 6px; flex-wrap: wrap; }
.persp__source { font-size: 15px; font-weight: 700; margin-right: 8px; }
.persp__region { font-size: 11px; color: var(--text-faint); border: 1px solid var(--border); padding: 1px 6px; border-radius: 5px; }
.persp__stance { font-size: 14.5px; line-height: 1.7; color: var(--text); margin: 4px 0 8px; }
.persp__orig { font-size: 13px; color: var(--text-dim); font-style: italic; line-height: 1.5; margin: 0 0 10px; word-break: break-word; }
.persp__link { display: inline-block; font-size: 13px; font-weight: 600; color: var(--accent); padding: 5px 12px; border: 1px solid var(--border); border-radius: 8px; }
.persp__link:active { background: var(--bg-elev2); }

/* callout: why it matters / what's next */
.callout {
  background: var(--callout-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 4px 0 4px;
}
.callout__title { font-size: 14px; font-weight: 700; color: var(--accent); margin: 0 0 6px; }
.callout p { margin: 0; font-size: 15px; line-height: 1.75; color: var(--text); }

/* glossary */
.glossary { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-top: 8px; box-shadow: var(--shadow); }
.glossary dt { font-weight: 700; font-size: 14px; margin-top: 10px; }
.glossary dt:first-child { margin-top: 0; }
.glossary dd { margin: 2px 0 0; font-size: 13.5px; color: var(--text-dim); line-height: 1.6; }
.glossary__orig { color: var(--text-faint); font-style: italic; }

/* sources list */
.srclist { margin: 6px 0 0; padding: 0; list-style: none; }
.srclist li { margin-bottom: 8px; font-size: 13.5px; }
.srclist a { word-break: break-word; }
.srclist .srclist__src { color: var(--text-dim); margin-right: 6px; }

/* ---------- Archive ---------- */
.archive-item {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.archive-item:active { -webkit-transform: scale(0.99); transform: scale(0.99); }
.archive-item__date { flex: 1 1 auto; }
.archive-item__count { font-size: 13px; color: var(--text-faint); font-weight: 500; }
.archive-item.is-current .archive-item__date::after {
  content: "今日";
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 5px;
  margin-left: 8px;
  font-weight: 700;
}

/* ---------- Footer ---------- */
.app-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-bottom: calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-faint);
  background: var(--bg-elev);
}
.app-footer__link { font-weight: 600; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(70px + var(--safe-bottom));
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  box-shadow: var(--shadow);
  -webkit-animation: toastIn 0.25s ease both;
  animation: toastIn 0.25s ease both;
}

/* ===== Animations (iOS 13 safe: transform + opacity) ===== */
@-webkit-keyframes cardIn { from { opacity: 0; -webkit-transform: translateY(10px); } to { opacity: 1; -webkit-transform: none; } }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@-webkit-keyframes viewInFwd { from { opacity: 0; -webkit-transform: translate3d(22px, 0, 0); } to { opacity: 1; -webkit-transform: none; } }
@keyframes viewInFwd { from { opacity: 0; transform: translate3d(22px, 0, 0); } to { opacity: 1; transform: none; } }

@-webkit-keyframes viewInBack { from { opacity: 0; -webkit-transform: translate3d(-22px, 0, 0); } to { opacity: 1; -webkit-transform: none; } }
@keyframes viewInBack { from { opacity: 0; transform: translate3d(-22px, 0, 0); } to { opacity: 1; transform: none; } }

@-webkit-keyframes toastIn { from { opacity: 0; -webkit-transform: translate(-50%, 8px); } to { opacity: 1; -webkit-transform: translate(-50%, 0); } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.view-anim-fwd {
  -webkit-animation: viewInFwd 0.28s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  animation: viewInFwd 0.28s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}
.view-anim-back {
  -webkit-animation: viewInBack 0.28s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  animation: viewInBack 0.28s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* Respect reduced-motion: disable all entrance/transition motion */
@media (prefers-reduced-motion: reduce) {
  .card, .view-anim-fwd, .view-anim-back, .toast { -webkit-animation: none !important; animation: none !important; }
  .iconbtn, .tab, .card, .archive-item { -webkit-transition: none !important; transition: none !important; }
}

@media (min-width: 600px) {
  .app-header__title { font-size: 20px; }
  .detail__title { font-size: 26px; }
}
