:root {
  --bg: #f1f2f4;
  --card: #ffffff;
  --text: #1b1c1f;
  --muted: #868b94;
  --accent: #3b6ef6;
  --accent-weak: #eaf1ff;
  --border: #e8e9ee;
  --danger: #e5484d;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 6px 20px rgba(16,24,40,.04);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", sans-serif;
  background: var(--bg); color: var(--text);
  overscroll-behavior-y: none; -webkit-font-smoothing: antialiased;
}
.bg-glow { display: none; }

.screen { display: none; min-height: 100%; padding-bottom: calc(28px + var(--safe-bottom)); }
.screen.active { display: block; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(12px + var(--safe-top)) 14px 10px;
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.brand { font-size: 23px; margin: 0; flex: 1; font-weight: 800; letter-spacing: -0.02em; }
.detail-title { font-size: 17px; font-weight: 700; flex: 1; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: none; background: transparent; color: #5b606b; width: 40px; height: 40px; border-radius: 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background .15s; }
.icon-btn:active { background: #e7e8ec; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#btn-detail-menu svg circle { fill: currentColor; stroke: none; }

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

/* 搜尋 */
.search-wrap { position: relative; padding: 4px 16px 12px; }
.search-icn { position: absolute; left: 30px; top: 50%; transform: translateY(-70%); width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
#search { width: 100%; padding: 12px 14px 12px 40px; border-radius: 13px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 16px; box-shadow: var(--shadow); }
#search::placeholder { color: var(--muted); }
#search:focus { outline: none; border-color: var(--accent); }

/* 分類篩選列 */
.filter-bar { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 10px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.fchip { flex: none; border: 1px solid var(--border); background: var(--card); color: #5b606b; font-size: 13.5px; font-weight: 600; padding: 7px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.fchip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.storage-line { padding: 0 22px 8px; color: var(--muted); font-size: 12px; }

/* 卡片分類標籤 */
.chip-i.cat { color: var(--accent); }

/* 分類選擇彈窗 */
.cat-options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.cat-opt { border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 14px; padding: 9px 15px; border-radius: 999px; cursor: pointer; }
.cat-opt.active { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* 清單卡片 */
.rec-list { list-style: none; margin: 0; padding: 0 14px 120px; }
.rec-item { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px 8px; margin-bottom: 12px; box-shadow: var(--shadow); cursor: pointer; transition: transform .1s; }
.rec-item:active { transform: scale(0.992); }
.rec-head { display: flex; align-items: flex-start; gap: 10px; }
.rec-title { flex: 1; margin: 0; font-size: 16.5px; font-weight: 700; color: var(--accent); line-height: 1.35; word-break: break-word; }
.ai-btn { flex: none; display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--accent); color: var(--accent); background: #fff; font-size: 12.5px; font-weight: 600; padding: 6px 11px; border-radius: 999px; cursor: pointer; }
.ai-btn svg { width: 14px; height: 14px; fill: currentColor; }

.chips { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0 4px; }
.chip-i { display: inline-flex; align-items: center; gap: 4px; color: #5b606b; font-size: 12.5px; }
.chip-i svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.preview { margin: 8px 0 2px; padding: 0; list-style: none; }
.preview li { position: relative; padding-left: 15px; margin-bottom: 5px; font-size: 14px; line-height: 1.5; color: #3d4149; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.preview li::before { content: ""; position: absolute; left: 3px; top: 8px; width: 4px; height: 4px; border-radius: 50%; background: #b9bdc6; }
.more-pts { color: var(--accent); font-size: 13px; font-weight: 600; margin: 6px 0 2px; }
.snippet { color: var(--muted); font-size: 13.5px; margin: 8px 0 2px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.rec-actions { display: flex; align-items: center; gap: 4px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.rec-actions .meta { color: var(--muted); font-size: 12.5px; margin-left: 4px; }
.rec-actions .spacer { flex: 1; }
.act { border: none; background: transparent; color: #6b707a; width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.act:active { background: #eef0f3; }
.act svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.act.play { color: var(--accent); }
.act.play svg { width: 22px; height: 22px; fill: currentColor; stroke: none; }
.act.del { color: #b9738c; }

.empty-hint { display: none; text-align: center; color: var(--muted); margin-top: 70px; padding: 0 30px; }
.empty-hint .empty-icn { font-size: 46px; opacity: .4; margin-bottom: 14px; }
.empty-hint p { line-height: 1.7; }
.empty-hint span { font-size: 13px; opacity: .8; }

/* FAB */
.fab-wrap { position: fixed; left: 0; right: 0; bottom: calc(24px + var(--safe-bottom)); display: flex; justify-content: center; pointer-events: none; }
.fab { pointer-events: auto; width: 66px; height: 66px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 24px rgba(59,110,246,.45); transition: transform .12s; }
.fab:active { transform: scale(0.92); }
.fab-dot { width: 24px; height: 24px; border-radius: 7px; background: #fff; }

/* 錄音畫面 */
#screen-record.active, #screen-progress.active { display: flex; align-items: center; justify-content: center; }
.rec-live { text-align: center; padding: 30px 24px calc(40px + var(--safe-bottom)); }
.rec-ring { position: relative; width: 168px; height: 168px; margin: 0 auto 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.rec-ring::before { content: ""; position: absolute; width: 168px; height: 168px; border-radius: 50%; border: 2px solid rgba(59,110,246,.4); animation: ring 1.8s ease-out infinite; }
@keyframes ring { 0% { transform: scale(0.8); opacity: .8; } 100% { transform: scale(1.25); opacity: 0; } }
.rec-ring-core { width: 96px; height: 96px; border-radius: 50%; background: var(--accent); box-shadow: 0 10px 30px rgba(59,110,246,.4); animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.rec-timer { font-size: 56px; font-weight: 300; font-variant-numeric: tabular-nums; }
.rec-status { color: var(--muted); margin: 10px 0 34px; font-size: 14px; }
.rec-controls { display: flex; gap: 12px; justify-content: center; }

/* 進度 */
.progress-box { text-align: center; padding: 0 34px; width: 100%; max-width: 420px; }
.progress-title { font-size: 17px; margin-top: 22px; font-weight: 700; }
.progress-detail { color: var(--muted); font-size: 13px; margin-top: 8px; min-height: 18px; line-height: 1.5; }
.spinner { width: 42px; height: 42px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto; animation: spin .8s linear infinite; }
.spinner.sm { width: 20px; height: 20px; border-width: 2.5px; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 6px; background: var(--border); border-radius: 99px; margin-top: 22px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 99px; transition: width .25s; }

/* 詳情 */
.detail-meta { padding: 0 20px 14px; color: var(--muted); font-size: 13px; }
#player { width: calc(100% - 32px); height: 40px; margin: 0 16px 16px; }

.segmented { display: flex; gap: 8px; margin: 0 16px 16px; }
.segmented .seg { flex: none; border: none; background: #e9ebef; color: #5b606b; font-size: 14.5px; font-weight: 600; padding: 9px 18px; cursor: pointer; border-radius: 11px; transition: background .18s, color .18s; }
.segmented .seg.active { color: #fff; background: var(--accent); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* 摘要（Markdown 筆記排版） */
.summary-loading { display: flex; align-items: center; gap: 12px; justify-content: center; color: var(--muted); padding: 44px 0; font-size: 14px; }
.summary-loading[hidden] { display: none; }
.summary-empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.summary-empty p { margin-bottom: 18px; font-size: 14px; }
.summary-content { padding: 2px 20px 56px; }
.summary-content h4 { margin: 26px 0 12px; font-size: 17px; font-weight: 800; color: var(--text); }
.summary-content h4:first-child { margin-top: 4px; }
.summary-content h5 { margin: 16px 0 7px; font-size: 14px; font-weight: 700; color: #3d4149; }
.summary-content ul { margin: 0 0 8px; padding-left: 18px; list-style: none; }
.summary-content li { position: relative; padding-left: 16px; margin-bottom: 9px; line-height: 1.7; font-size: 15.5px; color: #2b2e34; }
.summary-content li::before { content: ""; position: absolute; left: 2px; top: 11px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.summary-content ul ul { margin-top: 9px; }
.summary-content ul ul li::before { background: #b9bdc6; }
.summary-content strong { font-weight: 700; color: var(--text); }
.summary-content p { line-height: 1.7; color: #2b2e34; margin: 8px 0; }

/* 舊版摘要格式相容 */
.sum-block { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 17px; margin: 0 4px 12px; }
.sum-block h4 { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--accent); }
.sum-block ul { margin: 0; padding-left: 2px; list-style: none; }
.sum-block li { position: relative; padding-left: 20px; margin-bottom: 9px; line-height: 1.6; font-size: 15px; }
.sum-block li::before { content: ""; position: absolute; left: 4px; top: 9px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.sum-block.todos li::before { content: "☐"; left: 0; top: 0; width: auto; height: auto; background: none; color: var(--accent); }

/* 逐字稿 */
.transcript-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 18px 10px; }
.transcript-tools .hint { color: var(--muted); font-size: 12px; }
.transcript { padding: 2px 20px 56px; line-height: 1.85; font-size: 16px; white-space: pre-wrap; -webkit-user-select: text; user-select: text; color: #2b2e34; }

/* 按鈕 */
.btn { border: 1px solid var(--border); background: var(--card); color: var(--text); padding: 12px 18px; border-radius: 13px; font-size: 15.5px; font-weight: 600; cursor: pointer; transition: transform .1s; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; border: none; box-shadow: 0 6px 18px rgba(59,110,246,.35); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 7px 14px; font-size: 13px; border-radius: 10px; }
.btn.block { display: block; width: 100%; margin-bottom: 10px; text-align: center; }

/* 彈窗 */
.sheet { position: fixed; inset: 0; background: rgba(20,22,28,.35); display: flex; align-items: flex-end; z-index: 20; animation: fade .2s; }
.sheet[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.sheet-body { background: var(--card); width: 100%; border-radius: 24px 24px 0 0; padding: 12px 18px calc(20px + var(--safe-bottom)); animation: slideup .28s cubic-bezier(.3,.9,.3,1); }
@keyframes slideup { from { transform: translateY(30px); } }
.sheet-grip { width: 40px; height: 5px; border-radius: 99px; background: #d8dade; margin: 2px auto 16px; }
.sheet-body h2 { margin: 0 0 12px; font-size: 18px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 2px; border-bottom: 1px solid var(--border); }
.row:last-of-type { border-bottom: none; }
.row small { color: var(--muted); }
.row select { background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; font-size: 14px; }
.row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.mono { font-family: ui-monospace, monospace; color: var(--muted); }
#btn-close-settings { margin-top: 16px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%); background: #23262d; color: #fff; padding: 11px 20px; border-radius: 999px; font-size: 14px; z-index: 40; max-width: 86%; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast[hidden] { display: none; }

/* 問 AI 對話 */
.chat-list { padding: 6px 16px 4px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 26px 20px 6px; }
.chat-msg { max-width: 86%; padding: 11px 14px; border-radius: 17px; line-height: 1.6; font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.chat-msg.q { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.chat-msg.a { align-self: flex-start; background: #fff; border: 1px solid var(--border); color: #2b2e34; border-bottom-left-radius: 5px; }
.chat-msg.a.pending { color: var(--muted); }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 16px 6px; }
.chip { border: 1px solid var(--border); background: var(--card); color: #5b606b; font-size: 13px; padding: 7px 13px; border-radius: 999px; cursor: pointer; }
.chip:active { background: #eef0f3; }
.chat-input { display: flex; gap: 8px; padding: 8px 16px calc(16px + var(--safe-bottom)); position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 35%); }
.chat-input input { flex: 1; padding: 12px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 16px; }
.chat-input input:focus { outline: none; border-color: var(--accent); }
.chat-input .btn { padding: 0; width: 46px; height: 46px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; }
.chat-input .btn svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
