/* =============================================================
   style.css — 版面與外觀
   版面：整個網頁固定成「一個螢幕高」，上面是小屋，下面是對話，
   只有訊息列表自己捲動，聊天時小屋一直看得到。
   ============================================================= */

:root {
  --bg: #f6efe4;        /* 奶油底色 */
  --card: #fffaf2;
  --ink: #4a3428;       /* 深咖啡文字 */
  --muted: #9a8270;
  --line: #e2d3c0;
  --accent: #8c3b3b;    /* 酒紅，呼應臥室 */
  --glass: rgba(255, 250, 242, 0.72); /* 疊在場景上的半透明底色 */
  --fade: 400ms;        /* 淡入淡出時間 */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* 整頁 = 一個螢幕高（dvh 會扣掉 Safari 的網址列；舊瀏覽器退回 vh） */
.app {
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 12px calc(env(safe-area-inset-bottom) + 8px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  min-height: 40px;            /* 手指好按 */
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
}
button.is-here,
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button:disabled { opacity: 0.45; }
button.link {
  border: none;
  background: none;
  padding: 4px 2px;
  min-height: 32px;
  color: var(--muted);
}

/* 疊在場景上的半透明元件（毛玻璃） */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 1px 4px rgba(74, 52, 40, 0.15);
}

/* ---------- 右上角設定選單按鈕（固定在螢幕上） ---------- */
.menu-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  right: max(16px, calc(50% - 240px + 16px));
  z-index: 200;
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

/* ---------- 場景 ---------- */
/* 寬度最多佔螢幕高的 55%，矮螢幕時對話區才不會被擠沒 */
.scene-wrap {
  position: relative;
  flex: none;
  width: min(100%, 55dvh);
  margin: 0 auto;
  transition: opacity var(--fade);
}

.scene {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;          /* 實際比例由 main.js 依設定檔填入 */
  overflow: hidden;
}

/* 每個圖層都蓋滿整個場景；色塊則用百分比定位 */
.layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.layer img { width: 100%; height: 100%; display: block; }
.layer .ph { position: absolute; border-radius: 6px; }

/* ---------- 角色 ---------- */
.char {
  position: absolute;
  pointer-events: none;
  transition: opacity var(--fade);
}
/* 整張畫布的角色圖：與背景同尺寸，直接蓋滿 */
.char.is-sprite { inset: 0; }
.char.is-sprite img { width: 100%; height: 100%; display: block; }
/* 色塊佔位：以腳底中心點為基準 */
.char.is-placeholder { transform: translate(-50%, -100%); }
.char .ph {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  color: #fff;
  font-size: 11px;
  line-height: 1.2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.hidden { opacity: 0; }

/* ---------- 左上：場景切換 ---------- */
.scene-switch {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 100;
}
.scene-switch > button {
  min-height: 34px;
  padding: 4px 12px;
  font-size: 13px;
}
.scene-menu {
  margin-top: 4px;
  border-radius: 14px;
  padding: 4px;
  display: grid;
  gap: 2px;
  min-width: 120px;
}
.scene-menu[hidden] { display: none; }
.scene-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: none;
  background: none;
  border-radius: 10px;
  min-height: 36px;
  text-align: left;
}
.scene-menu-item.is-active { background: rgba(140, 59, 59, 0.12); color: var(--accent); font-weight: 600; }
.oc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

/* ---------- 左下：OC 狀態小框 ---------- */
.status-pill {
  position: absolute;
  left: 4px;
  bottom: 4px;
  z-index: 100;
  max-width: 68%;
  min-height: 0;
  padding: 6px 12px;
  border-radius: 14px;
  display: grid;
  gap: 1px;
  text-align: left;
  font-size: 12px;
  line-height: 1.35;
  cursor: default;
}
.status-pill.is-away { cursor: pointer; }
.status-pill.is-away .st-sub { color: var(--accent); font-weight: 600; }
.st-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-row b { font-weight: 600; }
.st-sub { color: var(--muted); }
.st-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ---------- 右下：跟隨／手動 ---------- */
.follow-btn {
  position: absolute;
  right: 4px;
  bottom: 4px;
  z-index: 100;
  min-height: 32px;
  padding: 4px 12px;
  font-size: 12px;
}
.follow-btn.is-on { color: var(--accent); font-weight: 600; }

/* ---------- 「我去」按鈕列（手動模式） ---------- */
.me-move { flex: none; display: flex; align-items: center; gap: 8px; }
.me-move[hidden] { display: none; }
.me-move button { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.row-label { color: var(--muted); font-size: 13px; flex: none; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 對話區：填滿剩下的高度 ---------- */
.chat {
  flex: 1;
  min-height: 0;               /* 讓裡面的列表可以縮小、自己捲動 */
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border-radius: 16px;
  padding: 0 10px 10px;
  box-shadow: 0 1px 4px rgba(74, 52, 40, 0.08);
}
.chat.is-collapsed { flex: none; }
.chat.is-collapsed .msg-list,
.chat.is-collapsed .chat-error { display: none; }

/* 收合把手：一條細橫線，沒有文字 */
.chat-handle {
  flex: none;
  align-self: stretch;
  min-height: 22px;
  padding: 0;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-handle span {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}

.msg-list {
  flex: 1;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 0 2px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.msg-list:empty::before {
  content: "還沒有訊息，跟他打聲招呼吧。";
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 12px 0;
}
.msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg time { display: block; font-size: 11px; color: var(--muted); }
.msg.from-oc { align-self: flex-start; background: #f1e6d6; border-bottom-left-radius: 4px; }
.msg.from-me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.from-me time { color: rgba(255, 255, 255, 0.75); text-align: right; }
.msg.is-event {
  align-self: center;
  background: none;
  color: var(--muted);
  font-size: 12px;
  padding: 0;
}
.msg.is-typing { color: var(--muted); }
.msg:not(.is-event):not(.is-typing) { cursor: pointer; }

/* 訊息底部：時間、版本切換 */
.msg-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.from-me .msg-meta { justify-content: flex-end; }
.versions { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); }
.versions button {
  min-height: 28px;
  padding: 0 8px;
  border: none;
  background: none;
  font-size: 16px;
  color: var(--ink);
}
.versions button:disabled { opacity: 0.3; }

/* 點訊息後出現的按鈕列 */
.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-actions button { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.msg.is-event .msg-actions { justify-content: center; }

/* 原位編輯 */
.msg.is-editing { max-width: 100%; width: 100%; background: #fff; color: var(--ink); border: 1px solid var(--line); }
.msg-editor textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  border: none;
  outline: none;
  resize: vertical;
  background: transparent;
  color: var(--ink);
}
.msg-editor .msg-actions { justify-content: flex-end; }

.chat-error {
  flex: none;
  margin: 0;
  font-size: 13px;
  color: #b23b3b;
  background: #fbeaea;
  border-radius: 10px;
  padding: 8px 10px;
}

/* 輸入列 */
.chat-input { flex: none; display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea {
  flex: 1;
  font: inherit;
  font-size: 16px;            /* 16px 以上，iPhone 點輸入框才不會自動放大 */
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  resize: none;
  max-height: 120px;
  background: #fff;
  color: var(--ink);
}

/* ---------- 設定選單（☰） ---------- */
.menu-dialog {
  border: none;
  border-radius: 18px;
  padding: 0;
  width: min(94vw, 460px);
  max-height: 88vh;
  background: var(--card);
  color: var(--ink);
}
.menu-dialog::backdrop { background: rgba(40, 25, 15, 0.45); }
.menu-page { padding: 14px 16px 18px; display: grid; gap: 12px; }
.menu-page[hidden] { display: none; }
.menu-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu-head h2 { margin: 0; font-size: 18px; flex: 1; }
.menu-head .menu-back { flex: none; }

.menu-list { display: grid; gap: 6px; }
.menu-list button {
  display: grid;
  gap: 2px;
  text-align: left;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 15px;
}
.menu-list small { color: var(--muted); font-size: 12px; }

.settings fieldset { border: 1px solid #eadcca; border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; margin: 0; }
.settings legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.settings label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.settings input, .settings textarea, .settings select {
  font: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.settings label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
.settings label.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }

/* 測試工具 */
.row { display: flex; align-items: center; gap: 10px; }
.warn-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.warn-list { margin: 0; padding-left: 18px; font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.warn-list:empty::before { content: "（沒有警告）"; margin-left: -18px; }

/* ---------- 對話頭像 ---------- */
.msg-row { display: flex; align-items: flex-end; gap: 6px; }
.msg-row.is-oc { justify-content: flex-start; }
.msg-row.is-me { flex-direction: row-reverse; }
.msg-row.is-event { justify-content: center; }
.msg-row .msg.is-editing { flex: 1; }
.msg-avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.st-dot.has-avatar { width: 18px; height: 18px; }

/* ---------- 人設頁的頭像 ---------- */
.persona-forms { display: grid; gap: 12px; }
.avatar-row { display: flex; align-items: center; gap: 8px; }
.avatar-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- 剖面圖 ---------- */
.scene.is-zooming { transition: transform 450ms ease-in; }
.ov-area {
  position: absolute;
  z-index: 10;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
}
.ov-area:active { background: rgba(255, 250, 242, 0.18); }
.ov-label {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink);
  pointer-events: none;
}
.ov-area.is-locked .ov-label { opacity: 0.6; }
.ov-markers { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.ov-marker-group {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  gap: 2px;
}
.ov-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

/* 剖面圖時狀態框可以點；短暫提示 */
.status-pill.is-clickable { cursor: pointer; }
.scene-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 150;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  pointer-events: none;
}
.scene-toast[hidden] { display: none; }
.scene-wrap { overflow: hidden; } /* 放大動畫不要蓋到對話區 */

/* ---------- 頭像裁切 ---------- */
.crop-box {
  position: relative;
  width: min(72vw, 300px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 12px;
  background: #222;
  touch-action: none;          /* 拖曳時不要捲動頁面 */
  cursor: grab;
}
.crop-box img {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
/* 圓框：框外變暗，圓框內就是頭像 */
.crop-box::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.9);
  pointer-events: none;
}
.crop-zoom { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.crop-zoom input { width: 100%; accent-color: var(--accent); }

/* ---------- 未讀數（對話收合時，顯示在把手旁） ---------- */
.chat-handle { position: relative; }
.unread-badge {
  position: absolute;
  left: calc(50% + 28px);
  top: 3px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
}
.unread-badge[hidden] { display: none; }

/* ---------- 對話下方功能區 ---------- */
.feature-bar { flex: none; display: flex; gap: 8px; overflow-x: auto; }
.feature-bar button { min-height: 36px; padding: 6px 14px; font-size: 13px; }

/* ---------- 近況紀錄 ---------- */
.recap-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.recap-list:empty::before { content: "還沒有近況。離開一段時間再回來，就會看到他做了什麼。"; color: var(--muted); font-size: 14px; }
.recap-item { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.recap-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.recap-item p { margin: 4px 0 0; font-size: 14px; line-height: 1.6; }

/* 主動訊息設定：勿擾時間並排 */
.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* 場景選單的分組標題（組與組之間有分隔線） */
.scene-menu-title {
  padding: 6px 10px 2px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.05em;
}
.scene-menu-title:not(:first-child) {
  margin-top: 4px;
  border-top: 1px solid rgba(154, 130, 112, 0.3);
  padding-top: 8px;
}

/* 24 小時制時間選擇（時：分） */
.time24 { display: flex; align-items: center; gap: 4px; color: var(--ink); }
.time24 select { flex: 1; text-align: center; }

/* ---------- 天氣 ---------- */
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; min-width: 0; }
.pick-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.pick-list button { width: 100%; text-align: left; border-radius: 10px; font-size: 13px; }
.weather-body { display: grid; gap: 8px; }
.weather-row { display: flex; gap: 12px; font-size: 14px; }
.weather-row b { flex: none; width: 36px; color: var(--muted); font-weight: 500; }
.weather-row b { width: 64px; }
.weather-row span { white-space: pre-line; }
.weather-row.is-warning { color: #b23b3b; }
.test-output {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}
.test-output[hidden] { display: none; }

/* ---------- 日程 ---------- */
.segmented { display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: #f1e6d6; }
.segmented button { flex: 1; min-height: 32px; padding: 4px 10px; border: none; background: none; font-size: 13px; }
.segmented button.is-active { background: #fff; box-shadow: 0 1px 3px rgba(74, 52, 40, 0.15); font-weight: 600; }
.schedule-group { font-size: 12px; color: var(--muted); margin: 6px 2px 2px; }
#schedule-groups { display: grid; gap: 6px; }
.plan-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  border-radius: 12px;
  padding: 8px 12px;
  border-left: 4px solid var(--line);
}
.plan-row.is-me { border-left-color: #5b8bd0; }
.plan-row.is-oc { border-left-color: #e0a43a; }
.plan-when { flex: none; min-width: 44px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.plan-main { display: grid; gap: 1px; min-width: 0; }
.plan-main b { font-weight: 600; font-size: 14px; }
.plan-main small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.schedule-past summary { font-size: 13px; color: var(--muted); padding: 6px 2px; cursor: pointer; }
.schedule-past .plan-row { margin-top: 6px; opacity: 0.7; }
#sch-time-row[hidden] { display: none; }
#row-gemini-key[hidden], #row-vertex-key[hidden] { display: none; }

/* ---------- 設定裡的清單列（帳號、常出現的人） ---------- */
.list-rows { display: grid; gap: 6px; }
.list-row { display: grid; gap: 2px; text-align: left; border-radius: 12px; padding: 8px 12px; }
.list-row b { font-weight: 600; font-size: 14px; }
.list-row small { color: var(--muted); font-size: 12px; }

/* ---------- 社群 ---------- */
.social-dialog { height: 88vh; }
.acct-chips { display: flex; gap: 6px; overflow-x: auto; }
.acct-chip { flex: none; min-height: 30px; padding: 4px 12px; font-size: 12px; }
.acct-chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.social-feed { display: grid; gap: 12px; }

.s-avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.s-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.s-comment .s-avatar { width: 26px; height: 26px; font-size: 11px; }

.s-profile { display: flex; gap: 12px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.s-profile .s-avatar { width: 56px; height: 56px; font-size: 20px; }
.s-profile-info { display: grid; gap: 2px; min-width: 0; }
.s-profile-info p { margin: 4px 0; font-size: 14px; white-space: pre-wrap; }
.s-profile-info small { color: var(--muted); font-size: 12px; }

.s-post { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 8px; }
.s-head { display: flex; align-items: center; gap: 8px; }
.s-who { display: grid; flex: 1; min-width: 0; }
.s-who b, .s-who-line b { font-size: 14px; font-weight: 600; }
.s-who small, .s-who-line small { color: var(--muted); font-size: 12px; }
.s-text { margin: 0; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }

/* 照片描述卡 */
.s-photo {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: linear-gradient(135deg, #efe2cf, #e3cdb3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  text-align: center;
}
.s-photo.is-small { aspect-ratio: 16 / 9; }
.s-photo-icon { font-size: 26px; opacity: 0.7; }
.s-photo-text { font-size: 14px; color: var(--ink); line-height: 1.6; }

.s-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.s-act {
  min-height: 28px;
  padding: 2px 6px;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--muted);
}
.s-act.is-liked { color: #d0455b; }
.s-delete { margin-left: auto; }
.s-count { font-size: 13px; color: var(--muted); }

.s-x-row { display: flex; gap: 10px; }
.s-x-main { flex: 1; min-width: 0; display: grid; gap: 6px; }

.s-comments { display: grid; gap: 6px; border-top: 1px solid #f1e6d6; padding-top: 6px; }
.s-comment { display: flex; gap: 8px; align-items: flex-start; }
.s-comment.is-reply { margin-left: 34px; }
.s-comment-body { min-width: 0; font-size: 13px; line-height: 1.5; }
.s-comment-body b { font-weight: 600; }
.s-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.s-meta .s-act { min-height: 24px; font-size: 12px; padding: 0 4px; }
.s-more { justify-self: start; border: none; background: none; min-height: 24px; padding: 0; font-size: 12px; color: var(--muted); }
.s-comment-form { display: flex; gap: 6px; align-items: center; }
.s-comment-form input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; }
.s-comment-as { font-size: 12px; padding: 4px; border-radius: 8px; border: 1px solid var(--line); max-width: 90px; }
/* 長文字（例如照片描述）要能換行，不要把卡片撐寬 */
.menu-page > *, .social-feed > *, .s-post > *, .s-x-main > * { min-width: 0; }
.s-photo-text { max-width: 100%; word-break: break-word; }

/* ---------- 聊天照片 ---------- */
.attach-btn {
  flex: none;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
}
.attach-preview { flex: none; display: flex; gap: 6px; overflow-x: auto; }
.attach-preview[hidden] { display: none; }
.attach-item { position: relative; flex: none; }
.attach-item img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; display: block; }
.attach-item button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
  background: var(--ink);
  color: #fff;
  border: none;
}

/* 訊息裡的照片：1 張大圖、2 張以上排成格子 */
.msg-images { display: grid; gap: 3px; margin: 2px 0 4px; border-radius: 10px; overflow: hidden; }
.msg-images.count-1 { grid-template-columns: 1fr; }
.msg-images.count-2, .msg-images.count-4 { grid-template-columns: 1fr 1fr; }
.msg-images.count-3 { grid-template-columns: 1fr 1fr 1fr; }
.msg-images img {
  width: 100%;
  display: block;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.06);
  min-height: 60px;
  cursor: zoom-in;
}
.msg-images.count-1 img { max-height: 260px; }
.msg-images:not(.count-1) img { aspect-ratio: 1 / 1; }
.msg-images img.is-missing { min-height: 40px; }

/* 看大圖 */
.image-viewer { border: none; padding: 0; background: transparent; max-width: 96vw; max-height: 92vh; }
.image-viewer::backdrop { background: rgba(0, 0, 0, 0.85); }
.image-viewer img { display: block; max-width: 96vw; max-height: 92vh; object-fit: contain; border-radius: 8px; }

/* ---------- 社群照片 ---------- */
.compose-photos { display: grid; gap: 6px; justify-items: start; }
/* IG 風：可以左右滑的正方形大圖 */
.s-carousel-box { position: relative; }
.s-carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.s-carousel::-webkit-scrollbar { display: none; }
.s-carousel img {
  flex: none;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  scroll-snap-align: start;
  background: rgba(0, 0, 0, 0.06);
  cursor: zoom-in;
}
.s-carousel-count {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
}
/* X 風：小格子 */
.s-photos-x { display: grid; gap: 3px; border-radius: 12px; overflow: hidden; }
.s-photos-x.count-1 { grid-template-columns: 1fr; }
.s-photos-x.count-2, .s-photos-x.count-4 { grid-template-columns: 1fr 1fr; }
.s-photos-x.count-3 { grid-template-columns: 1fr 1fr 1fr; }
.s-photos-x img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; background: rgba(0, 0, 0, 0.06); cursor: zoom-in; }
.s-photos-x:not(.count-1) img { aspect-ratio: 1 / 1; }
