/* friendbook：Threads 風美術 — 黑白、細線、圓形頭像、圓角膠囊、系統字體 */
* { box-sizing: border-box; }
:root {
  --ink: #000;
  --muted: #999;
  --line: #eee;
  --bg: #fff;
}
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; }

.view[hidden], .modal[hidden] { display: none !important; }

/* ---------- 登入 ---------- */
#view-auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h1 { font-size: 34px; letter-spacing: -1px; margin: 0; }
.tagline { color: var(--muted); margin: 6px 0 24px; }
.fields label { display: block; margin-bottom: 14px; }
.fields input { width: 100%; padding: 10px 12px; border: 1px solid var(--ink); border-radius: 999px; outline: none; }
.fields input:focus { box-shadow: 0 0 0 2px #0002; }
.switch { margin-top: 12px; color: var(--muted); }
.switch .ghost { margin-left: 6px; text-decoration: underline; }

/* ---------- 按鈕 ---------- */
.primary {
  background: var(--ink); color: #fff; border: 0; border-radius: 999px;
  padding: 10px 18px; font-weight: 600;
}
.primary:active { transform: scale(.97); }
.ghost { background: none; border: 0; color: var(--ink); padding: 6px 10px; border-radius: 999px; }
.ghost:hover { background: #f5f5f5; }
.wide { width: 100%; }
.compose-fab { position: fixed; bottom: 26px; right: 26px; font-size: 22px; width: 56px; height: 56px; padding: 0; }

/* ---------- 頂列與分頁 ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.logo { font-weight: 800; font-size: 19px; letter-spacing: -0.5px; }
.spacer { flex: 1; }
.me-chip { color: var(--muted); cursor: pointer; }
.me-chip:hover { color: var(--ink); }

.tabs {
  display: flex; gap: 4px; justify-content: center;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 53px; background: var(--bg); z-index: 4;
}
.tab {
  background: #f5f5f5; border: 0; border-radius: 999px; padding: 8px 16px; color: #666;
}
.tab.active { background: var(--ink); color: #fff; }

/* ---------- 動態牆：單欄、文字為主、細分隔線 ---------- */
.feed { max-width: 520px; margin: 0 auto; }
.post { padding: 16px 20px; }
.post + .post { border-top: 1px solid var(--line); }
.post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink); color: #fff; font-weight: 700; line-height: 34px;
  text-align: center; font-size: 14px; flex: none; cursor: pointer;
}
.post-user { font-weight: 600; cursor: pointer; }
.post-user:hover { text-decoration: underline; }
.post-time { color: var(--muted); font-size: 13px; }
.post-text { white-space: pre-wrap; overflow-wrap: break-word; line-height: 1.45; }
.post-tag { color: var(--muted); font-weight: 600; }
.post-actions { display: flex; align-items: center; gap: 14px; margin-top: 10px; color: var(--muted); }
.act { background: none; border: 0; padding: 2px 6px; color: var(--muted); }
.act.on { color: var(--ink); font-weight: 700; }
.act:hover { color: var(--ink); }
.act.del { margin-left: auto; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

#feed-more-row { text-align: center; padding: 12px 0 90px; }
#feed-more { border: 1px solid var(--line); border-radius: 999px; }

/* ---------- 貼文詳情 ---------- */
.comment-row { display: flex; gap: 8px; padding: 12px 0; }
.comment-row input { flex: 1; padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px; outline: none; }
.comment-row input:focus { border-color: var(--ink); }
.comment { border-top: 1px solid var(--line); padding: 10px 0; }
.comment-head { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.comment-user { font-weight: 600; cursor: pointer; }
.comment .del { margin-left: auto; color: var(--muted); font-size: 12px; }

/* ---------- 個人頁 ---------- */
.profile-head { text-align: center; padding: 24px 0 16px; }
.profile-head .avatar { width: 64px; height: 64px; line-height: 64px; font-size: 24px; margin: 0 auto 10px; }
.profile-name { font-size: 22px; font-weight: 800; }
.profile-bio { color: var(--muted); margin: 6px 0; }
.profile-stats { display: flex; justify-content: center; gap: 24px; color: var(--muted); font-size: 14px; margin-bottom: 14px; }

/* ---------- 視窗 ---------- */
.modal {
  position: fixed; inset: 0; background: #000c; display: flex;
  align-items: flex-start; justify-content: center; padding: 24px 12px; z-index: 20;
}
.modal-card {
  background: #fff; border-radius: 20px; width: 100%; max-width: 520px;
  max-height: calc(100vh - 48px); overflow-y: auto; padding: 18px 20px;
}
.close-x { float: right; }

/* ---------- 發文 ---------- */
#compose-text {
  width: 100%; min-height: 140px; border: 0; resize: vertical;
  outline: none; font-size: 17px; padding: 4px 2px;
}
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.modal-actions .error { margin-right: auto; }

.error { color: #d33; font-size: 13px; min-height: 18px; }

/* 字數計數：正常灰字，超限轉紅色警示 */
.count { color: var(--muted); font-size: 13px; margin-right: auto; }
.count.over { color: #d33; font-weight: 700; }

/* 分頁列右側的檢視模式切換 */
.tab.mode { padding: 8px 12px; }
.tab.mode.active { outline: 2px solid #0002; }

/* YouTube 嵌入影片：16:9、圓角、寬度吃滿欄 */
.yt-embed {
  position: relative; width: 100%; aspect-ratio: 16/9;
  margin: 10px 0; border-radius: 12px; overflow: hidden; background: #000;
}
.yt-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* 貼文圖片與發文預覽 */
.post-image {
  display: block; width: 100%; border-radius: 14px; margin-top: 8px;
  border: 1px solid var(--line); cursor: pointer;
}
.compose-image { position: relative; margin: 8px 0 4px; }
.compose-image img {
  display: block; max-width: 100%; max-height: 260px;
  border-radius: 12px; border: 1px solid var(--line);
}
.compose-image button {
  position: absolute; top: 6px; right: 6px;
  background: #0009; color: #fff; border-radius: 50%;
  width: 28px; height: 28px; padding: 0; line-height: 1;
}

/* Markdown 排版元素 */
.post-text h4, .post-text h5, .post-text h6 { margin: 6px 0 4px; line-height: 1.3; }
.post-text h4 { font-size: 17px; }
.post-text h5 { font-size: 16px; }
.post-text h6 { font-size: 15px; }
.post-text p { margin: 6px 0; }
.post-text ul { margin: 6px 0; padding-left: 22px; }
.post-text blockquote { margin: 6px 0; padding: 2px 0 2px 12px; border-left: 3px solid #ddd; color: #444; }
.post-text code {
  background: #f2f2f2; border-radius: 4px; padding: 1px 5px;
  font: 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.post-text pre {
  background: #f7f7f7; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; overflow-x: auto; margin: 8px 0;
}
.post-text pre code { background: none; padding: 0; font-size: 13px; }

/* GFM 表格 */
.post-text table { border-collapse: collapse; margin: 8px 0; font-size: 14px; display: block; overflow-x: auto; }
.post-text th, .post-text td { border: 1px solid #ddd; padding: 5px 10px; text-align: left; }
.post-text th { background: #fafafa; font-weight: 700; }

/* mermaid：圖吃滿欄、可捲動；還沒渲染前顯示原始碼 */
.post-text .mermaid { margin: 10px 0; text-align: center; overflow-x: auto; background: #fff; }
.post-text .mermaid svg { max-width: 100%; height: auto; }
.post-text .mermaid-source {
  margin: 10px 0; padding: 10px 12px; border: 1px dashed #ccc; border-radius: 10px;
  white-space: pre-wrap; font: 13px ui-monospace, Menlo, monospace; color: #555;
}

/* KaTeX 行內與區塊數學；太寬的式子可橫向捲動 */
.post-text .math-display { margin: 10px 0; overflow-x: auto; padding: 4px 0; }
.post-text span.math-tex { white-space: normal; }
