:root {
  color-scheme: light;
  --color-primary: #1d4f91;
  --color-breaking: #c8102e;
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-text: #142033;
  --color-muted: #3d4c5f;
  --color-line: #d5dce6;
  --color-chip: #e7edf5;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(20, 32, 51, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 32, 51, 0.08);
  --font-sans: "Noto Sans TC", "PingFang HK", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --main-col: 812px;
  --side-col: 300px;
  --bg: var(--color-bg);
  --card: var(--color-surface);
  --text: var(--color-text);
  --muted: var(--color-muted);
  --line: var(--color-line);
  --accent: var(--color-primary);
  --accent-ink: #ffffff;
  --chip: var(--color-chip);
  --danger: var(--color-breaking);
  --shadow: var(--shadow-sm);
  font-family: var(--font-sans);
}

html.dark {
  color-scheme: dark;
  --color-bg: #0e141c;
  --color-surface: #17202b;
  --color-text: #f3f6fa;
  --color-muted: #c9d3df;
  --color-line: #2e3b4c;
  --color-chip: #243140;
  --color-primary: #9ec0ef;
  --accent-ink: #0e141c;
  --shadow-sm: none;
  --shadow-md: none;
}

* { box-sizing: border-box; }
html, body, #root { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
img { max-width: 100%; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: var(--space-3); top: -40px; background: var(--accent); color: var(--accent-ink);
  padding: var(--space-2) var(--space-3); z-index: 30; border-radius: var(--radius-sm);
}
.skip-link:focus { top: var(--space-3); }

.page { width: min(100% - 32px, var(--main-col)); margin: 0 auto; padding: 0 0 var(--space-7); }

.chrome {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); margin: 0 -2px; padding: 0 2px 2px;
  border-bottom: 1px solid var(--line);
}
.masthead { display: flex; align-items: center; gap: var(--space-2); min-height: 52px; }
.masthead-title { margin: 0; font-size: inherit; font-weight: inherit; line-height: 1; flex: none; }
.logo-link { display: flex; align-items: center; min-height: 40px; text-decoration: none; color: inherit; }
.logo-link img { height: 36px; width: auto; }
.logo-word { font-family: var(--font-serif); font-size: 1.35rem; font-weight: 700; letter-spacing: 0.04em; }
.logo-link .logo-compact,
.logo-link .logo-dark { display: none; }
html.dark .logo-link .logo-light { display: none; }
html.dark .logo-link .logo-full.logo-dark { display: block; }

.search-bar { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; }
.search-toggle { display: none; }
.search-bar input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: var(--radius-pill);
  padding: 8px 14px; min-height: 40px; font-size: 16px;
}
.header-actions { display: flex; align-items: center; gap: 4px; flex: none; }
a.chip { color: inherit; text-decoration: none; }
.digest-strip {
  display: flex; gap: 10px; align-items: center; overflow: auto; margin-top: 8px;
  padding: 8px 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.digest-strip a, .analysis-link { font-weight: 700; text-decoration: none; }
.analysis-box {
  display: flex; gap: 8px; align-items: center; margin-top: 8px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--chip);
  color: inherit; text-decoration: none; font-weight: 700; font-size: 0.92rem;
}
.trending .analysis-box { font-size: 0.82rem; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: var(--radius-pill); padding: 2px 8px; font-size: 0.8rem; font-weight: 700; }
.icon-btn, .chip, .primary, .bookmark, .install-banner button {
  border: 1px solid var(--line); background: var(--card); border-radius: var(--radius-pill);
  min-height: 40px; min-width: 40px; padding: 6px 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 0 0 auto;
  white-space: nowrap;
}
.header-actions .icon-btn { padding: 6px; position: relative; }
.icon-btn.active, .chip.active, .primary, .bookmark.on {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
}
.icon-btn:disabled { opacity: 0.6; cursor: progress; }
.count-badge {
  position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--radius-pill); background: var(--color-breaking); color: #fff; font-size: 10px; line-height: 16px;
}

.tab-bar { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.tab-bar > .chip { flex: none; }
.filters {
  display: flex; gap: var(--space-2); overflow-x: auto; flex-wrap: nowrap; min-width: 0;
  padding: 6px 0; scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.filters-slim { padding-top: 0; padding-bottom: 6px; }
.chip { padding: 6px 12px; }
.filter-panel { display: grid; gap: 4px; padding-bottom: 8px; }
.filter-panel .filters { padding-top: 2px; }

.region-icon {
  width: 16px; height: 16px; display: inline-block; background: currentColor; flex: none;
  mask-size: contain; mask-repeat: no-repeat; mask-position: center; mask-mode: alpha;
  -webkit-mask-size: contain; -webkit-mask-repeat: no-repeat; -webkit-mask-position: center;
}
.region-icon-lg { width: 48px; height: 48px; }

.layout { display: grid; gap: var(--space-4); margin-top: var(--space-4); }
.top-stories { display: grid; gap: var(--space-3); }
.secondary-list { display: none; }
.layout, .top-stories, .news-grid, #news, .story { min-width: 0; }
.story {
  display: grid; gap: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); height: 100%;
}
.story-media {
  display: block; width: 100%; max-width: 100%; aspect-ratio: 16 / 9; max-height: 200px;
  overflow: hidden; background: var(--chip);
}
.thumb, .thumb-fallback {
  display: block; width: 100%; height: 100%; max-width: 100%; max-height: 200px;
  object-fit: cover; background: var(--chip);
}
.thumb-fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 10px;
  background: linear-gradient(155deg, color-mix(in srgb, var(--ph, var(--accent)) 28%, var(--color-surface)), color-mix(in srgb, var(--ph, var(--accent)) 8%, var(--color-bg)));
  color: color-mix(in srgb, var(--ph, var(--accent)) 82%, var(--color-text));
}
.thumb-source {
  max-width: 100%; font-size: 0.8rem; font-weight: 700; line-height: 1.25; text-align: center;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.story-body { display: grid; gap: 6px; padding: var(--space-3) var(--space-4) var(--space-4); align-content: start; }
.story-kicker, .story-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; color: var(--muted); font-size: 0.92rem; }
.kicker-region { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--text); }
.breaking { background: var(--color-breaking); color: #fff; border-radius: var(--radius-pill); padding: 2px 8px; font-size: 0.875rem; font-weight: 700; }
.cluster-badge { border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 2px 8px; font-size: 0.875rem; }
.story-title {
  font-family: var(--font-serif); font-size: 1.12rem; line-height: 1.4; margin: 0; font-weight: 700;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.story-title a { color: inherit; text-decoration: none; }
.story-title a:hover { text-decoration: underline; }
.story-hero .story-media { max-height: 220px; }
.story-hero .thumb, .story-hero .thumb-fallback { max-height: 220px; }
.story-hero .story-title { font-size: clamp(1.35rem, 2.4vw, 1.85rem); line-height: 1.32; -webkit-line-clamp: 3; }
.story-hero .region-icon-lg { width: 64px; height: 64px; }
.story-compact { display: flex; flex-direction: row; align-items: stretch; min-height: 0; }
.story-compact .story-media { flex: none; width: 112px; }
.story-compact .story-media { max-height: 72px; aspect-ratio: 16 / 9; }
.story-compact .thumb, .story-compact .thumb-fallback { width: 112px; height: 100%; max-height: 72px; min-height: 0; }
.story-compact .thumb-source { font-size: 0.68rem; }
.story-compact .story-body { padding: 8px 10px; gap: 4px; }
.story-compact .story-title { font-size: 0.98rem; -webkit-line-clamp: 2; }
.story-compact .region-icon-lg { width: 28px; height: 28px; }
.source-tag, .read-original { font-weight: 700; text-decoration: none; }
.favicon { width: 16px; height: 16px; border-radius: 3px; }
.bookmark { margin-left: auto; min-height: 36px; padding: 4px 10px; }
.read-original { font-size: 0.92rem; }
.card-credit, .app-footer, .notice, .side-card p { color: var(--muted); }
.card-credit { margin: 0; font-size: 0.85rem; }
.news-grid { display: grid; gap: var(--space-4); margin-top: var(--space-4); }
.trending, .side-card, .status-panel, .notice {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); box-shadow: var(--shadow);
}
.trending h2, .side-card h2, .status-panel h2 { font-family: var(--font-serif); margin: 0 0 var(--space-3); font-size: 1.25rem; }
.trending ol { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.trending li { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 8px; align-items: start; }
.trending .rank { font-family: var(--font-serif); font-size: 1.25rem; font-weight: 700; color: var(--accent); line-height: 1.2; }
.trending a { color: inherit; font-weight: 700; text-decoration: none; }
.trending a:hover { text-decoration: underline; }
.trending .cluster-badge { display: inline-flex; margin-top: 4px; }
.sidebar { display: grid; gap: var(--space-4); align-content: start; }
.ad-slot { width: 100%; overflow: hidden; }
.ad-slot-banner { min-height: 90px; }
.ad-slot-feed { min-height: 280px; grid-column: 1 / -1; }
.ad-slot-sidebar { width: 300px; max-width: 100%; min-height: 600px; position: static; }
.ad-slot .adsbygoogle { display: block; width: 100%; min-height: inherit; }
.share-row, .app-footer { margin-top: var(--space-5); }
.more { margin-top: var(--space-4); width: 100%; }
.install-banner {
  position: sticky; bottom: 12px; display: flex; justify-content: space-between; gap: var(--space-3); align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-3); margin-top: var(--space-4);
}
.lang-wrap { position: relative; }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 25; list-style: none; margin: 0; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md); min-width: 160px;
}
.lang-menu button { width: 100%; text-align: left; border: 0; background: transparent; border-radius: var(--radius-sm); padding: 8px; cursor: pointer; min-height: 40px; }
.lang-menu button.active, .lang-menu button:hover { background: var(--chip); }
.skeleton-line { height: 14px; border-radius: var(--radius-sm); margin: 10px 0; background: var(--chip); }
.skeleton-line.short { width: 40%; }
.skeleton .thumb-fallback { background: var(--chip); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (max-width: 700px) {
  .logo-link .logo-full { display: none !important; }
  .logo-link .logo-compact.logo-light { display: block; }
  html.dark .logo-link .logo-compact.logo-light { display: none !important; }
  html.dark .logo-link .logo-compact.logo-dark { display: block !important; }
  .logo-link img { height: 28px; }
  .search-bar { flex: none; }
  .search-toggle { display: inline-flex; }
  .search-bar input { display: none; }
  .search-bar.open {
    position: absolute; left: 0; right: 0; top: 48px; z-index: 5; background: var(--bg); padding: 6px 0 8px;
  }
  .search-bar.open input { display: block; }
  .masthead { position: relative; }
  .install-banner { flex-direction: column; align-items: stretch; }
  .bookmark { margin-left: 0; }
  /* Dense mobile cards: image on the left so photos don't dominate the screen. */
  .news-grid .story {
    display: flex; flex-direction: row; align-items: flex-start; min-width: 0; min-height: 0;
  }
  .news-grid .story-media {
    flex: none; width: 112px; height: 112px; max-width: 112px; max-height: 112px; aspect-ratio: 1 / 1;
  }
  .news-grid .thumb, .news-grid .thumb-fallback {
    width: 112px; height: 112px; max-width: 112px; max-height: 112px; min-height: 0; object-fit: cover;
  }
  .news-grid .thumb-source { font-size: 0.68rem; }
  .news-grid .story-body { padding: 8px 10px; gap: 4px; min-width: 0; }
  .news-grid .story-title { font-size: 0.98rem; -webkit-line-clamp: 3; }
  .news-grid .region-icon-lg { width: 28px; height: 28px; }
  .news-grid .card-credit { display: none; }
  .top-stories .story-hero .story-media {
    max-height: 180px; aspect-ratio: 16 / 9; width: 100%;
  }
  .top-stories .story-hero .thumb,
  .top-stories .story-hero .thumb-fallback {
    max-height: 180px; width: 100%; height: 100%; object-fit: cover;
  }
  .top-stories .story-hero .story-title { font-size: 1.15rem; }
}

@media (min-width: 700px) {
  .news-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1200px) {
  .page { width: min(100% - 32px, calc(var(--main-col) + var(--side-col) + var(--space-5))); }
  .layout { grid-template-columns: minmax(0, var(--main-col)) var(--side-col); align-items: start; }
  .sidebar { width: var(--side-col); position: static; }
  .top-stories { grid-template-columns: minmax(0, 1.35fr) minmax(220px, 0.8fr); align-items: stretch; }
  .secondary-list { display: flex; flex-direction: column; gap: 8px; }
  .story-hero .story-media, .story-hero .thumb, .story-hero .thumb-fallback { max-height: 280px; }
}

/* HK weather strip (HKO/EPD). Fixed min-height so it doesn't shift the page when it loads. */
.hk-weather {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-height: 48px; margin-top: 8px;
  padding: 6px 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); font-size: 0.9rem;
}
.sidebar .hk-weather { margin-top: 0; }
.hk-weather a { color: inherit; text-decoration: none; }
.hk-now { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; }
.hk-now img, .hk-icon-ph { width: 28px; height: 28px; }
html.dark .hk-now img { filter: invert(1) hue-rotate(180deg); }
.hk-temp { font-weight: 700; font-size: 1.05rem; }
.hk-meta, .hk-credit { color: var(--muted); font-size: 0.82rem; }
.hk-credit { margin-left: auto; }
.hk-aqhi { border-radius: var(--radius-pill); padding: 2px 8px; font-weight: 700; font-size: 0.82rem; border: 1px solid var(--line); }
.aqhi-low { color: #0b6b4f; } .aqhi-mid { color: #8a4b08; } .aqhi-high { color: var(--color-breaking); }
html.dark .aqhi-low { color: #7fd6b4; } html.dark .aqhi-mid { color: #f0b46a; }
.hk-warnings { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.hk-warning { background: var(--color-breaking); color: #fff !important; border-radius: var(--radius-pill); padding: 2px 10px; font-weight: 700; font-size: 0.82rem; }
/* 熱搜 */
.topics { margin-top: 8px; }
.sidebar .topics { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); margin-top: 0; }
.topics-title { font-family: var(--font-serif); font-size: 1.05rem; margin: 0 0 6px; }
.sidebar .topics-title { font-size: 1.25rem; margin-bottom: var(--space-3); }
.topics-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.sidebar .topics-row { flex-wrap: wrap; overflow: visible; }
.topic { gap: 6px; min-height: 40px; font-size: 0.9rem; }
.topic-rank { color: var(--color-breaking); font-weight: 700; }
.topic.active .topic-rank { color: inherit; }
.topic-count { color: var(--muted); font-size: 0.75rem; }
.topic.active .topic-count { color: inherit; }
/* New headlines + back to top */
.new-items {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 40; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: var(--radius-pill);
  min-height: 40px; padding: 8px 16px; box-shadow: var(--shadow-md), 0 4px 14px rgba(0,0,0,0.18);
}
.back-to-top { position: fixed; right: 16px; bottom: 20px; z-index: 30; box-shadow: var(--shadow-md); width: 44px; height: 44px; }
.card-links { display: flex; gap: 16px; flex-wrap: wrap; }
.card-links .read-original { min-height: 32px; display: inline-flex; align-items: center; }
a.cluster-link { color: inherit; text-decoration: none; min-height: 28px; display: inline-flex; align-items: center; }
a.cluster-link:hover { border-color: var(--accent); }
