/* 聊得來：寫實聊天 app 風格。手機優先，亮／暗色都有 */
:root {
  --bg: #f7f3ef; --surface: #ffffff; --surface2: #f0ebe6; --ink: #2b2522; --muted: #8b817a; --line: #e7dfd8;
  --accent: #ff6b5a; --accent-ink: #ffffff; --accent-soft: #ffe7e3; --her: #ffffff; --me: #ff6b5a; --me-ink: #fff;
  --good: #2f9e6b; --ok: #c99a2e; --bad: #d4513f; --narr: #7d736c;
  --os-bg: #fff6e8; --os-ink: #6b4a1a; --coach-bg: #eaf4ff; --coach-ink: #1f4c7a;
  --shadow: 0 8px 28px rgba(60, 40, 30, .14);
  --r: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412; --surface: #221e1b; --surface2: #2b2623; --ink: #f2ebe5; --muted: #a0958d; --line: #3a332e;
    --accent: #ff7a6a; --accent-soft: #3e2622; --her: #2b2623; --me: #e85d4d;
    --narr: #a89d95; --os-bg: #3a2f1f; --os-ink: #f2d6a8; --coach-bg: #1d2c3d; --coach-ink: #b9d8f7;
    --shadow: 0 8px 28px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
#app { max-width: 560px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* ---------- 頁首／分頁 ---------- */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: .5px; }
.top .sub { color: var(--muted); font-size: 13px; }
.back { border: 0; background: none; font-size: 26px; line-height: 1; padding: 4px 8px 4px 0; color: var(--accent); }
.page { flex: 1; padding: 12px 16px calc(88px + env(safe-area-inset-bottom)); }
.page.flush { padding: 0; }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs a { flex: 1; max-width: 140px; text-align: center; padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: 12px; position: relative; }
nav.tabs a .i { display: block; font-size: 22px; line-height: 28px; }
nav.tabs a.on { color: var(--accent); font-weight: 700; }
nav.tabs .dot { position: absolute; top: 6px; left: calc(50% + 10px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 11px; line-height: 16px; padding: 0 4px; }

/* ---------- 共用 ---------- */
.card { background: var(--surface); border-radius: var(--r); padding: 14px 16px; box-shadow: 0 1px 0 var(--line); margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn { border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 700; background: var(--accent); color: var(--accent-ink); min-height: 46px; }
.btn.ghost { background: var(--surface2); color: var(--ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.good { color: var(--good); } .chip.ok { color: var(--ok); } .chip.bad { color: var(--bad); }
.av { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; background: var(--surface2); flex: none; display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.av.s { width: 36px; height: 36px; }
.av.l { width: 72px; height: 72px; }
.av.ended { filter: grayscale(1); opacity: .55; }
h2 { font-size: 17px; margin: 18px 0 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 聊天列表 ---------- */
.list a { display: flex; gap: 12px; align-items: center; padding: 10px 0; color: inherit; text-decoration: none; border-bottom: 1px solid var(--line); }
.list .name { font-weight: 700; }
.list .time { color: var(--muted); font-size: 12px; }
.list .unread { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
.typing { color: var(--accent); }

/* ---------- 聊天室 ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.msgs { flex: 1; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 6px; }
.m { max-width: 78%; padding: 8px 12px; border-radius: 18px; word-break: break-word; white-space: pre-wrap; animation: pop .22s ease-out both; }
.m.her { align-self: flex-start; background: var(--her); border-bottom-left-radius: 6px; box-shadow: 0 1px 0 var(--line); }
.m.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 6px; }
.m.narr { align-self: center; max-width: 92%; background: none; color: var(--narr); font-style: italic; font-size: 14px; text-align: center; padding: 4px 8px; }
.m.face.her, .m.face.me { opacity: .92; }
.m.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface2); border-radius: 99px; padding: 3px 12px; }
.m.ended { color: var(--bad); text-align: center; max-width: 92%; border-radius: 12px; }
.m.end { align-self: center; display: flex; gap: 8px; align-items: center; font-size: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 4px 6px 4px 12px; }
.m.end button { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 4px 10px; font-weight: 700; font-size: 13px; }
.m.os { align-self: flex-start; background: var(--os-bg); color: var(--os-ink); font-size: 14px; border-radius: 12px; max-width: 88%; }
.m.coach { align-self: flex-start; background: var(--coach-bg); color: var(--coach-ink); font-size: 14px; border-radius: 12px; max-width: 88%; }
.m.os b, .m.coach b { font-weight: 700; margin-right: 4px; }
.typing-b { align-self: flex-start; background: var(--her); border-radius: 18px; padding: 10px 14px; box-shadow: 0 1px 0 var(--line); }
.typing-b i { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing-b i:nth-child(2) { animation-delay: .2s; } .typing-b i:nth-child(3) { animation-delay: .4s; }
.hint { text-align: center; color: var(--muted); font-size: 13px; padding: 6px 16px 14px; }
.banner { margin: 8px 12px; padding: 12px 14px; border-radius: 14px; background: var(--accent-soft); display: flex; align-items: center; gap: 10px; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- 選擇區（滑卡／多選） ---------- */
.dock { position: sticky; bottom: 0; z-index: 4; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 80%, transparent); }
.swipe { position: relative; height: 172px; touch-action: none; user-select: none; -webkit-user-select: none; }
.swipe .sc { position: absolute; inset: 0; background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; will-change: transform; cursor: grab; }
.swipe .sc.fly { transition: transform .28s ease-in, opacity .28s; }
.swipe .sc.back { transition: transform .22s cubic-bezier(.2, .9, .3, 1.3); }
.swipe .q { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.swipe .opts { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.swipe .opt { border: 2px solid var(--line); border-radius: 14px; padding: 8px 10px; font-size: 15px; display: flex; flex-direction: column; justify-content: center; background: var(--surface); text-align: left; transition: border-color .1s, background .1s; }
.swipe .opt .arr { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.swipe .opt.hot { border-color: var(--accent); background: var(--accent-soft); }
.multi { display: flex; flex-direction: column; gap: 8px; }
.multi button { border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 10px 14px; text-align: left; font-size: 15px; box-shadow: 0 1px 0 var(--line); }
.multi button:active { border-color: var(--accent); background: var(--accent-soft); }
.flag { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 0; text-decoration: underline; }

/* ---------- 見面／練習的全螢幕場景 ---------- */
.scene-hero { position: relative; height: 150px; overflow: hidden; }
.scene-hero img { width: 100%; height: 100%; object-fit: cover; filter: blur(2px) brightness(.75); transform: scale(1.05); }
.scene-hero .cap { position: absolute; left: 16px; right: 16px; bottom: 12px; color: #fff; text-shadow: 0 1px 6px rgba(0,0,0,.5); }
.scene-hero .cap b { font-size: 20px; display: block; }

/* ---------- 讀訊號 ---------- */
.sig { position: relative; min-height: 300px; touch-action: none; user-select: none; -webkit-user-select: none; margin-top: 8px; }
.sig .sc { position: absolute; inset: 0; background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 10px; will-change: transform; }
.sig .ctx { color: var(--muted); font-size: 14px; }
.sig .her { font-size: 20px; font-weight: 600; }
.sig .nr { color: var(--narr); font-style: italic; }
.sig .lr { margin-top: auto; display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.sig .lr span.hot { color: var(--accent); font-weight: 700; }
.sig-res { margin-top: 12px; }
.sig-res .v { font-size: 20px; font-weight: 800; }
.v.good { color: var(--good); } .v.bad { color: var(--bad); }
.lr-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

/* ---------- 檔案 ---------- */
.photos { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 6px; border-radius: 0 0 22px 22px; }
.photos img { flex: none; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; scroll-snap-align: center; background: var(--surface2); }
.photos::-webkit-scrollbar { display: none; }
.pdots { display: flex; justify-content: center; gap: 6px; margin: 8px 0; }
.pdots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.stages { display: flex; gap: 4px; margin: 10px 0 4px; }
.stages i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.stages i.on { background: var(--accent); }
.traits { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- 回放／彈窗 ---------- */
#modal { position: fixed; inset: 0; z-index: 20; background: rgba(20, 14, 10, .5); display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
#modal .sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
#modal h3 { margin: 0 0 4px; font-size: 20px; }
.rp { background: var(--surface); border-radius: 16px; padding: 12px 14px; margin: 10px 0; }
.rp .h { color: var(--muted); font-size: 14px; }
.rp .pick { margin: 6px 0; font-weight: 700; }
.rp .pick.late::after { content: '（隔太久才回）'; font-weight: 400; color: var(--bad); font-size: 12px; }
.rp .os { background: var(--os-bg); color: var(--os-ink); border-radius: 10px; padding: 6px 10px; font-size: 14px; margin: 4px 0; }
.rp .why { background: var(--coach-bg); color: var(--coach-ink); border-radius: 10px; padding: 6px 10px; font-size: 14px; margin: 4px 0; }
.rp details { margin-top: 6px; font-size: 14px; }
.rp details summary { color: var(--muted); cursor: pointer; }
.rp .alt { border-left: 3px solid var(--line); padding-left: 10px; margin: 6px 0; }
.meter { display: flex; gap: 10px; font-size: 13px; color: var(--muted); }
.meter b { color: var(--ink); }
.result { font-size: 26px; font-weight: 800; }
.result.good { color: var(--good); } .result.ok { color: var(--ok); } .result.bad { color: var(--bad); }

/* ---------- 遇見 ---------- */
.dots { display: inline-flex; gap: 5px; vertical-align: middle; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.dots i.off { background: var(--line); }
.meet-card { display: flex; gap: 12px; align-items: center; }
.toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 30; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 32px); animation: pop .2s; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; background: var(--accent); }
textarea { width: 100%; min-height: 90px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 10px; font: 13px/1.4 ui-monospace, monospace; }
.debug { border: 1px dashed var(--muted); }
