:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --line: #e2dfd8;
  --accent: #e8730c;
  --accent-soft: #fdf0e3;
  --ok: #1d7a46;
  --bad: #c62828;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --card: #202020;
    --text: #ececec;
    --muted: #a0a0a0;
    --line: #353535;
    --accent: #ff8a2b;
    --accent-soft: #3a2614;
    --ok: #4cc283;
    --bad: #ff6b6b;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
}
.wrap { max-width: 900px; margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.orange { color: var(--accent); }

.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
h1 { font-size: 18px; margin: 0; }
h1 span { color: var(--accent); }
h2 { font-size: 17px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 15px; margin: 20px 0 8px; }
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; }

.mode-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--bg); }
.mode-btn { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 999px; font: inherit; cursor: pointer; }
.mode-btn.active { background: var(--accent); color: #fff; }
.mode-hint { margin: 16px 0 0; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 16px 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 8px; }

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .grid { grid-template-columns: 1fr; } }

.source { border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px; margin: 12px 0; }
.source-head { display: flex; justify-content: space-between; align-items: center; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 16px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: progress; }

.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.status { color: var(--muted); font-size: 14px; }
.status.error { color: var(--bad); }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; }
.thumb img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumb button { position: absolute; top: 2px; right: 2px; border: 0; border-radius: 50%; width: 22px; height: 22px; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin-bottom: 4px; }
.login-card .btn { width: 100%; margin-top: 8px; }
.turnstile { margin: 12px 0 4px; min-height: 65px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.search-row { display: flex; gap: 8px; margin: 4px 0 8px; }
.search-row input { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 10px; }
.tab { font: inherit; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 4px 14px; border-radius: 999px; cursor: pointer; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.news-list { display: grid; gap: 6px; }
.news-item { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.news-item .meta { font-size: 12px; color: var(--muted); }
.news-item .body { flex: 1; min-width: 0; }
.news-item .body a { color: var(--text); text-decoration: none; }
.news-item .body a:hover { text-decoration: underline; }
.news-item input[type=checkbox] { width: auto; margin-top: 5px; accent-color: var(--accent); }
.news-item.selected { border-color: var(--accent); background: var(--accent-soft); }

#articleHint { white-space: pre-line; }
/* 新聞內文編輯區：像 Pages 一樣段落之間有固定間距（Enter 新段落、Shift+Enter 段內換行） */
.article-editor { font: inherit; line-height: 1.7; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-height: 240px; max-height: 70vh; overflow-y: auto; resize: vertical; white-space: pre-wrap; overflow-wrap: anywhere; }
.article-editor:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.article-editor p, .article-editor div { margin: 0 0 12px; }
.article-editor > :last-child { margin-bottom: 0; }
.article-editor p.sub { font-weight: 700; margin-top: 20px; }
.article-editor p.sub:first-child { margin-top: 0; }
.cover-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cover-controls .tabs { margin: 0; }
.tab:disabled { opacity: .5; cursor: progress; }
.tone-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.tone-pick select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.tone-hint { margin-top: -8px; }
.app-version { position: fixed; right: 10px; bottom: 6px; font-size: 11px; color: var(--muted); opacity: .7; pointer-events: none; }

/* 來源卡片收合 */
.source-head { gap: 8px; }
.source-head .row { flex-shrink: 0; }
.source-summary { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source.collapsed { padding-top: 8px; padding-bottom: 8px; }
.source.collapsed > :not(.source-head) { display: none; }
.source:not(.collapsed) .source-summary { visibility: hidden; }
.files { display: grid; gap: 6px; }
.file-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--accent-soft); }
.file-item span { overflow-wrap: anywhere; }

.titles { display: grid; gap: 8px; }
.title-opt { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.title-opt:has(input[type=radio]:checked) { border-color: var(--accent); background: var(--accent-soft); }
.title-opt input[type=radio] { width: auto; accent-color: var(--accent); }
.title-opt .title-text { flex: 1; min-width: 0; border: 0; background: transparent; padding: 4px; font: inherit; line-height: 1.5; color: inherit; resize: none; overflow: hidden; }
.title-opt.custom { border-style: dashed; }
/* 標題右邊的複製圖示按鈕 */
.icon-btn { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--line); background: var(--card); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.copied { color: #2e9e5b; }

.badge { font-size: 13px; padding: 2px 10px; border-radius: 999px; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--bad); }

.copybox { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; word-break: break-word; }
.kv { display: grid; gap: 4px; }
.kv-item .card-head h3 { margin-top: 12px; }

.covers { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.cover { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.cover-lines { font-size: 20px; font-weight: 700; line-height: 1.5; margin: 6px 0; }
.cover-lines mark { background: none; color: var(--accent); }
.cover-meta { font-size: 12px; color: var(--muted); }
.cover-meta .bad { color: var(--bad); }

/* 步驟鎖定：還沒走到的步驟變灰 */
.step.sub { background: var(--muted); }
.lock-note { display: none; }
.locked > .lock-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 4px 0 8px; padding: 10px 14px; border: 1px dashed var(--line); border-radius: 8px; background: var(--bg); color: var(--muted); font-size: 14px; }
#sourceGroup.locked > .lock-note { margin-top: 16px; }
.locked > :not(.lock-note):not(h2) { opacity: .4; filter: grayscale(1); pointer-events: none; user-select: none; }
.locked > h2 { color: var(--muted); }
.locked > h2 .step { background: var(--muted); }
.locked.compact > :not(.lock-note):not(h2) { display: none; }
.card.locked { background: transparent; }

/* Logo */
.brand { display: flex; align-items: center; }
.brand-link { display: flex; align-items: center; gap: 16px; color: inherit; text-decoration: none; }
.brand .logo { height: 26px; width: auto; display: block; }
.login-card .brand { flex-direction: column; align-items: flex-start; gap: 8px; }
.login-card .brand .logo { height: 40px; }

/* 找新聞：刷新時間與媒體篩選 */
.refresh-box { display: flex; align-items: center; gap: 8px; }
.news-filter-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: 4px 0 10px; }
.news-filter-row .tabs { margin: 0; }
/* 媒體下拉選單：自訂箭頭（系統預設箭頭會貼邊、文字不置中） */
.media-select {
  -webkit-appearance: none; appearance: none;
  font: inherit; font-size: 14px; line-height: 1.5; color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 36px 6px 16px; cursor: pointer;
  background-color: var(--bg);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 55%, calc(100% - 14px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.media-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ───────── 兩層畫面 ───────── */
#backBtn { font-weight: 500; }
.new-article { text-align: center; margin: 28px 0 48px; }
.new-article .btn { padding: 10px 28px; font-size: 16px; }
.new-article p { margin: 8px 0 0; }

/* ───────── 撰寫中：轉圈畫面 ───────── */
body.no-scroll { overflow: hidden; }
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 16px;
  background: rgba(20, 20, 20, .45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade-in .2s ease-out;
}
.overlay-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px 22px; box-shadow: 0 18px 50px rgba(0,0,0,.25);
}
.overlay-card h2 { justify-content: center; font-size: 18px; margin: 14px 0 4px; }
.overlay-msg { margin: 0; min-height: 3.4em; color: var(--text); font-size: 14px; }
.overlay-time { margin: 6px 0 4px; font-size: 26px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.overlay-time span { display: inline-block; min-width: 1.5em; }
.overlay-card .btn { margin-top: 12px; }

/* 住傳喵打字像素動畫（tools/writing-cat.mjs 產生） */
.writing-cat { display: block; width: 144px; height: auto; margin: 0 auto; image-rendering: pixelated; }
@keyframes spin-rotate { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* 其他 AI 動作（SEO 包、重新產生…）：狀態文字前的小轉圈 */
.status.busy::before {
  content: ""; display: inline-block; vertical-align: -2px;
  width: 13px; height: 13px; margin-right: 6px;
  border: 2px solid var(--line); border-top-color: #f8b62d; border-right-color: #f8b62d;
  border-radius: 50%; animation: spin-rotate .8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .status.busy::before { animation-duration: 3s; }
}

/* 第 6 步：WordPress 分類勾選 */
.wp-cats { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.wp-cat { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 14px; user-select: none; }
.wp-cat input { width: auto; margin: 0; accent-color: var(--accent); }
.wp-cat:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.wp-cat:has(input:disabled:not(:checked)) { opacity: .45; cursor: default; }
.wp-cat:has(input:disabled:checked) { cursor: default; }
#wpLinkRow { margin: 6px 0 0; font-weight: 600; }
/* 第 6 步：外部連結、延伸閱讀 */
.ext-links { display: grid; gap: 6px; margin: 4px 0 8px; }
.ext-row { display: grid; grid-template-columns: minmax(90px, 1fr) minmax(0, 2.4fr) auto auto; gap: 6px; align-items: center; }
.ext-row input { min-width: 0; }
.ext-row .icon-btn { width: 34px; }
.reading-row { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.reading-row select { flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.reading-row a.disabled { pointer-events: none; opacity: .4; }
@media (max-width: 560px) {
  .ext-row { grid-template-columns: 1fr auto auto; }
  .ext-row input[data-k=url] { grid-column: 1 / -1; grid-row: 2; }
}
#wpClose { margin-left: auto; }
/* 第 2 步：延伸議題（專題） */
.topics { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
.angle-tag { display: inline-block; margin-right: 6px; padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.source-no .topic-tag { margin-left: 6px; font-weight: 600; font-size: 12px; color: var(--accent); }

/* ───────── 手機與平板（V1.23） ───────── */
.btn { white-space: nowrap; }
.card-head .row { flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
@media (max-width: 600px) {
  /* 頂端列：第一行 logo＋名稱＋登出，第二行 回到上一步＋模式切換 */
  .topbar-inner { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding-top: 8px; padding-bottom: 8px; }
  .topbar-right { display: contents; }
  .brand { grid-column: 1; grid-row: 1; min-width: 0; }
  .brand-link { gap: 10px; }
  .brand .logo { height: 22px; }
  h1 { font-size: 16px; }
  .brand span { white-space: nowrap; }
  #logoutBtn { grid-column: 2; grid-row: 1; justify-self: end; }
  /* 第二行：左邊回到上一步、右邊模式切換（兩個放在同一行的兩端） */
  #backBtn { grid-column: 1; grid-row: 2; justify-self: start; }
  .mode-switch { grid-column: 1 / -1; grid-row: 2; justify-self: end; }
  .mode-btn { padding: 5px 12px; font-size: 14px; }
  /* iPhone 點輸入框時字小於 16px 會自動放大畫面 */
  input, textarea, select, .article-editor, .title-opt .title-text { font-size: 16px; }
  .card { padding-left: 14px; padding-right: 14px; }
  /* 主要按鈕改成整行，手指比較好按 */
  .actions > .btn.primary, .new-article .btn { width: 100%; }
}
@media (hover: none) {
  /* 觸控裝置：按鈕與勾選框大一點 */
  .btn.small { padding: 6px 12px; }
  .icon-btn { width: 40px; height: 40px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
}
/* 第 7 步：社群貼文 */
.social-text { width: 100%; resize: vertical; }
#socialResult h3.sub-h { font-size: 14px; color: var(--muted); margin-top: 10px; }
