:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1a1d23;
  --text-2: #555c68;
  --text-3: #8a909b;
  --border: #dfe2e8;
  --accent: #2f6fde;
  --accent-soft: #e3ecfc;
  --on-accent: #ffffff;
  --cat-semi: #b45f06;
  --cat-semi-soft: #fbeedd;
  --cat-ai: #7046c8;
  --cat-ai-soft: #eee7fb;
  --cat-mobile: #0f7f6c;
  --cat-mobile-soft: #dcf3ee;
  --imp: #d9480f;
  --ok: #2b8a3e;
  --bad: #c92a2a;
  --shadow: 0 1px 2px rgba(20, 25, 35, .06), 0 2px 8px rgba(20, 25, 35, .04);
  --radius: 14px;
  /* 英文字型放前面，避免中文字型把英文引號 ’ 畫成全形 */
  --font: "Segoe UI", Roboto, -apple-system, "Helvetica Neue", Arial, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #252932;
    --text: #e8eaee;
    --text-2: #aab0bb;
    --text-3: #7c838f;
    --border: #2e333d;
    --accent: #7aa7f5;
    --accent-soft: #22324f;
    --on-accent: #0d1424;
    --cat-semi: #f0a95a;
    --cat-semi-soft: #3a2a17;
    --cat-ai: #b79cf2;
    --cat-ai-soft: #2d2442;
    --cat-mobile: #5fd0bb;
    --cat-mobile-soft: #163731;
    --imp: #ff8a5c;
    --ok: #69db7c;
    --bad: #ff8787;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111317;
  --surface: #1a1d23;
  --surface-2: #252932;
  --text: #e8eaee;
  --text-2: #aab0bb;
  --text-3: #7c838f;
  --border: #2e333d;
  --accent: #7aa7f5;
  --accent-soft: #22324f;
  --on-accent: #0d1424;
  --cat-semi: #f0a95a;
  --cat-semi-soft: #3a2a17;
  --cat-ai: #b79cf2;
  --cat-ai-soft: #2d2442;
  --cat-mobile: #5fd0bb;
  --cat-mobile-soft: #163731;
  --imp: #ff8a5c;
  --ok: #69db7c;
  --bad: #ff8787;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

/* ---------- 版面：手機（預設） ---------- */

.app { min-height: 100dvh; }

.sidebar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.brand, .side-panel, .side-foot { display: none; }

.nav { display: flex; }
.nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  color: var(--text-3);
  text-decoration: none;
  font-size: 12px;
}
.nav a[aria-current="page"] { color: var(--accent); }
.nav svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.main {
  padding: 16px 16px calc(84px + env(safe-area-inset-bottom));
  max-width: 760px;
  margin: 0 auto;
  outline: none;
}

.mobile-controls { margin-bottom: 16px; }

/* ---------- 版面：平板（兩欄） ---------- */

@media (min-width: 768px) {
  .app {
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr);
  }
  .sidebar {
    position: sticky;
    top: 0;
    inset: auto;
    height: 100dvh;
    overflow-y: auto;
    border-top: 0;
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    padding: 0 8px;
  }
  .brand img { border-radius: 8px; }
  .side-panel { display: block; }
  .side-foot { display: block; margin: auto 8px 0; font-size: 12px; color: var(--text-3); }
  .nav { flex-direction: column; gap: 2px; }
  .nav a {
    flex-direction: row;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 15px;
    color: var(--text-2);
  }
  .nav a:hover { background: var(--surface-2); }
  .nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .nav svg { width: 20px; height: 20px; }
  .main { padding: 28px 32px 48px; max-width: 980px; margin: 0; }
  .mobile-controls { display: none; }
}

/* ---------- 共用元件 ---------- */

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: .01em;
}
.page-sub { margin: 0 0 20px; color: var(--text-2); font-size: 14px; }

.panel-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  margin: 0 8px 8px;
  letter-spacing: .04em;
}
.side-panel .group + .group { margin-top: 20px; }

.date-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.date-switch select {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 6px 4px;
  text-align: center;
  text-align-last: center;
  font-weight: 600;
  appearance: none;
  cursor: pointer;
}
.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 9px;
  background: transparent;
  cursor: pointer;
  color: var(--text-2);
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); }
.icon-btn:disabled { opacity: .3; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.side-panel .chips { flex-direction: column; gap: 4px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.side-panel .chip {
  border: 0;
  border-radius: 10px;
  background: transparent;
  padding: 8px 12px;
  justify-content: space-between;
  color: var(--text-2);
}
.side-panel .chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.side-panel .chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip .count { font-size: 12px; opacity: .75; font-variant-numeric: tabular-nums; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.semi { background: var(--cat-semi); }
.dot.ai { background: var(--cat-ai); }
.dot.mobile { background: var(--cat-mobile); }
.chip-label { display: inline-flex; align-items: center; gap: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.notice {
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 20px;
}

.empty { color: var(--text-3); text-align: center; padding: 48px 16px; }
.loading { color: var(--text-3); padding: 48px 0; text-align: center; }

/* ---------- 每日摘要 ---------- */

.headline { font-size: 15px; color: var(--text-2); margin: 0 0 20px; }

.sections { display: grid; gap: 16px; }
@media (min-width: 1100px) {
  .sections { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}

.section { padding: 18px 20px 8px; }
.section h2 {
  margin: 0 0 8px;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section h2 .more {
  margin-left: auto;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}
.points { list-style: none; margin: 0; padding: 0; }
.points li { padding: 10px 0; border-top: 1px solid var(--border); }
.points li:first-child { border-top: 0; }
.points .text { margin: 0 0 4px; font-size: 15px; line-height: 1.55; }
.links { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
.links a { text-decoration: none; }
.links a:hover { text-decoration: underline; }

/* ---------- 新聞列表 ---------- */

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text-2);
}
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
}
.seg button {
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-2);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.news { list-style: none; margin: 0; padding: 0; }
.news-item { padding: 14px 16px; }
.news-item + .news-item { margin-top: 10px; }
.news-item .title {
  display: block;
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
  margin: 0 0 6px;
}
.news-item .title:hover { color: var(--accent); }
.news-item .title:visited { color: var(--text-2); }
.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-size: 13px;
  color: var(--text-3);
}
.tag {
  font-size: 12px;
  border-radius: 6px;
  padding: 0 7px;
  line-height: 20px;
  font-weight: 500;
}
.tag.semi { background: var(--cat-semi-soft); color: var(--cat-semi); }
.tag.ai { background: var(--cat-ai-soft); color: var(--cat-ai); }
.tag.mobile { background: var(--cat-mobile-soft); color: var(--cat-mobile); }
.tag.lang { background: var(--surface-2); color: var(--text-2); }

.imp { display: inline-flex; gap: 2px; align-items: center; }
.imp i { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
.imp i.on { background: var(--imp); }

.also { font-size: 13px; margin-top: 6px; color: var(--text-3); }
.also a { text-decoration: none; }

/* ---------- 設定 ---------- */

.settings { display: grid; gap: 16px; }
.settings h2 { font-size: 15px; margin: 0; padding: 14px 18px 4px; color: var(--text-2); font-weight: 600; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  min-height: 56px;
}
.settings h2 + .row { border-top: 0; }
.row .desc { font-size: 13px; color: var(--text-3); margin: 2px 0 0; }
.row.sub { padding-left: 34px; }
.row[aria-disabled="true"] { opacity: .45; }
.row input[type="time"], .row select {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 6px 10px;
}

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background .15s;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled { cursor: default; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.danger { color: var(--bad); }

.src-list { list-style: none; margin: 0; padding: 0; }
.src-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 14px; }
.src-list .st { color: var(--text-3); font-variant-numeric: tabular-nums; }
.src-list .st.ok::before { content: "● "; color: var(--ok); }
.src-list .st.bad::before { content: "● "; color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 20;
}
@media (min-width: 768px) { .toast { bottom: 24px; } }

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

/* ---------- 第二階段：中文標題、推播裝置列 ---------- */

.news-item .title-zh { margin: -2px 0 6px; font-size: 14px; color: var(--text-2); line-height: 1.5; }
.row.device { flex-wrap: wrap; }
.row.device .desc { margin: 0; flex: 1 1 220px; font-size: 14px; color: var(--text-2); }
.row.device .btns { display: flex; gap: 8px; flex-wrap: wrap; }
