/* ===== 主题变量 ===== */
#phone {
    --bg: #f6f1ec; --card: #ffffff; --text: #2b2622; --sub: #8a8178; --line: #ece5de;
    --accent: #e88d67; --me: #95ec69; --me-text: #1a1a1a; --them: #ffffff; --chat-bg: #ededed;
    --input-bg: #f7f7f7; --danger: #e5484d; --note: #9b9b9b; --press: #f3eee9;
}
#phone[data-theme="dark"] {
    --bg: #1b1b1d; --card: #262628; --text: #ececec; --sub: #9a9a9f; --line: #333336;
    --them: #2f2f32; --chat-bg: #141416; --input-bg: #1f1f21; --note: #7c7c80; --press: #303033;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
    background: linear-gradient(135deg, #f3d9c9, #c9d6ea);
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea, select { background: transparent; }
select option { color: #222; }

/* ===== 手机外壳 ===== */
#phone {
    width: 390px; height: min(844px, calc(100vh - 40px));
    background: var(--bg); color: var(--text);
    border-radius: 44px;
    box-shadow: 0 0 0 10px #1f1f1f, 0 0 0 12px #3a3a3a, 0 30px 80px rgba(0,0,0,0.35);
    position: relative; overflow: hidden; display: flex; flex-direction: column;
}
@media (max-width: 500px) {
    body { background: #000; }
    #phone { width: 100vw; height: 100dvh; border-radius: 0; box-shadow: none; }
}
.statusbar {
    height: 44px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px; font-size: 15px; font-weight: 600; position: relative; z-index: 5; background: var(--bg);
}
.statusbar .icons { font-size: 12px; letter-spacing: 2px; }
@media (max-width: 500px) { .statusbar { height: calc(env(safe-area-inset-top, 0px) + 30px); padding-top: env(safe-area-inset-top, 0px); } }

#screens { flex: 1; position: relative; overflow: hidden; }
.screen {
    position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg);
    transform: translateX(100%); transition: transform 0.28s ease;
}
.screen.active { transform: translateX(0); }
.screen.behind { transform: translateX(-25%); }
.loading { position: absolute; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 48px; z-index: 100; }

/* ===== 顶栏 ===== */
.topbar {
    height: 48px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 4px;
    padding: 0 8px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.topbar .title { font-weight: 600; font-size: 17px; text-align: center; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; line-height: 1.2; }
.topbar .title small { display: block; font-size: 11px; font-weight: 400; color: var(--sub); }
.topbar > button { min-width: 40px; height: 40px; font-size: 22px; }
.topbar .text-btn { font-size: 15px; color: var(--accent); font-weight: 600; padding: 0 6px; }
.mode-pill { font-size: 12px !important; min-width: 0 !important; height: 26px !important; padding: 0 10px; border-radius: 13px; background: var(--card); border: 1px solid var(--line); }
.mode-pill.off { background: #3b3352; color: #fff; border-color: #3b3352; }
.search-top { flex: 1; height: 34px; border-radius: 8px; padding: 0 12px; background: var(--card); border: 1px solid var(--line); outline: none; font-size: 15px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ===== 桌面 ===== */
#home { background: linear-gradient(160deg, #f8e1d3 0%, #e9d5e8 50%, #cfdcef 100%) center / cover no-repeat; }
#phone[data-theme="dark"] #home { background-image: linear-gradient(160deg, #2b2433 0%, #1f2534 60%, #17202a 100%); }
#home.has-wallpaper { background-size: cover !important; background-position: center !important; }
#home .clock-big { text-align: center; margin-top: 36px; color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,0.2); }
#home .clock-big .t { font-size: 64px; font-weight: 300; line-height: 1; }
#home .clock-big .d { font-size: 15px; margin-top: 6px; }
.app-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 22px 0; padding: 40px 18px; }
.app { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.app .ic { width: 60px; height: 60px; border-radius: 15px; font-size: 30px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.85); box-shadow: 0 4px 12px rgba(0,0,0,0.08); position: relative; }
#phone[data-theme="dark"] .app .ic { background: rgba(60,60,66,0.85); }
.badge { position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff; font-size: 11px; min-width: 20px; height: 20px; border-radius: 10px; display: flex; align-items: center; justify-content: center; padding: 0 5px; text-shadow: none; font-weight: 600; z-index: 2; }
.dock { margin: auto 14px 18px; padding: 14px 10px; border-radius: 28px; background: rgba(255,255,255,0.35); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); display: grid; grid-template-columns: repeat(4, 1fr); }

/* ===== 列表 ===== */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; -webkit-user-select: none; }
.list-item:active { background: var(--press); }
.list-item.pinned { background: color-mix(in srgb, var(--card) 92%, var(--accent)); }
.list-item.disabled .meta { opacity: 0.45; }
.list-item .meta { flex: 1; min-width: 0; }
.list-item .name { font-size: 16px; font-weight: 500; }
.list-item .last { font-size: 13px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.list-item .time { font-size: 11px; color: var(--sub); align-self: flex-start; margin-top: 4px; flex-shrink: 0; }
.hl mark { background: color-mix(in srgb, var(--accent) 35%, transparent); color: inherit; border-radius: 2px; }
.empty { text-align: center; color: var(--sub); padding: 60px 30px; line-height: 1.8; font-size: 14px; }

.avatar { width: 46px; height: 46px; border-radius: 8px; flex-shrink: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff; font-weight: 600; background: #c9b8a8; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 40px; height: 40px; font-size: 17px; border-radius: 6px; }
.avatar.xs { width: 28px; height: 28px; font-size: 13px; border-radius: 5px; }
.avatar.tap { cursor: pointer; }
.group-avatar { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; padding: 2px; background: #ddd5cc; }
.group-avatar .avatar.mini { width: 100%; height: 100%; border-radius: 2px; font-size: 10px; }

/* ===== 聊天 ===== */
.chat-body { background: var(--chat-bg) center / cover no-repeat; padding: 10px 10px 16px; }
.chat-body.has-bg .time-sep, .chat-body.has-bg .note { background: rgba(0,0,0,0.25); color: #fff; padding: 2px 8px; border-radius: 4px; width: fit-content; margin-left: auto; margin-right: auto; }
.load-more { display: block; margin: 4px auto 10px; font-size: 13px; color: var(--accent); }
.time-sep { text-align: center; font-size: 12px; color: var(--note); margin: 14px 0 6px; }
.note { text-align: center; font-size: 12px; color: var(--note); margin: 8px 20px; line-height: 1.5; }
.note a { color: #576b95; cursor: pointer; }
.msg { display: flex; gap: 8px; margin: 10px 0; align-items: flex-start; }
.msg.me { flex-direction: row-reverse; }
.msg .col { display: flex; flex-direction: column; max-width: 72%; min-width: 0; }
.msg.me .col { align-items: flex-end; }
.msg .sender { font-size: 12px; color: var(--sub); margin: 0 0 3px 2px; }
.chat-body.has-bg .msg .sender { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.msg .edited { font-size: 11px; color: var(--note); margin-top: 2px; }
.flash .bubble, .flash.narration { animation: flash 1.6s; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }

.bubble {
    padding: 9px 12px; border-radius: 6px; font-size: 15px; line-height: 1.5;
    background: var(--them); position: relative; white-space: pre-wrap; word-break: break-word; user-select: text;
}
.msg.me .bubble { background: var(--me); color: var(--me-text); }
.msg .bubble::before { content: ""; position: absolute; top: 13px; left: -5px; border: 5px solid transparent; border-left: 0; border-right-color: var(--them); }
.msg.me .bubble::before { left: auto; right: -5px; border: 5px solid transparent; border-right: 0; border-left-color: var(--me); }
.msg.group-sender .bubble::before { top: 13px; }
.msg.err .bubble { background: #fde8e8; color: #9b1c1c; font-size: 13px; }
.msg.err .bubble::before { border-right-color: #fde8e8; }
.bubble .quote { font-size: 12px; color: rgba(0,0,0,0.5); background: rgba(0,0,0,0.06); border-radius: 4px; padding: 4px 8px; margin: -2px -4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
#phone[data-theme="dark"] .msg.them .bubble .quote { color: rgba(255,255,255,0.55); background: rgba(255,255,255,0.08); }
.typing .bubble { color: #999; }
.act { font-style: italic; opacity: 0.6; }
.typing .dots span { animation: blink 1.2s infinite; }
.typing .dots span:nth-child(2) { animation-delay: 0.2s; }
.typing .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.sticker-msg img { max-width: 120px; max-height: 120px; border-radius: 6px; display: block; }
.image-msg img { max-width: 180px; max-height: 240px; border-radius: 6px; display: block; cursor: zoom-in; }
.bubble.fakeimg { width: 180px; padding: 0; overflow: hidden; }
.bubble.fakeimg::before { display: none; }
.bubble.fakeimg .ph { height: 90px; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #e9e2da, #d7dde8); color: #6b6560; font-size: 14px; }
.bubble.fakeimg .desc { padding: 8px 10px; font-size: 13px; color: var(--sub); white-space: normal; }
.msg.me .bubble.fakeimg .desc { color: rgba(0,0,0,0.6); }
.bubble.voice { cursor: pointer; }
.bubble.voice .vline { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.msg.me .bubble.voice .vline { flex-direction: row-reverse; }
.bubble.voice .wave { letter-spacing: -2px; opacity: 0.7; }
.bubble.voice .vtext { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(0,0,0,0.1); font-size: 14px; }
.bubble.packet { width: 210px; padding: 0; overflow: hidden; color: #fff; cursor: pointer; }
.bubble.packet.red { background: #f39b3a; }
.bubble.packet.transfer { background: #f3a23a; }
.bubble.packet.done { opacity: 0.6; cursor: default; }
.msg .bubble.packet::before { border-right-color: #f39b3a !important; }
.msg.me .bubble.packet::before { border-left-color: #f39b3a !important; border-right-color: transparent !important; }
.packet .ptop { display: flex; gap: 10px; align-items: center; padding: 12px; }
.packet .picon { font-size: 30px; }
.packet .pnote { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.packet .pamount { font-size: 13px; opacity: 0.9; }
.packet .pbottom { background: #fff; color: #999; font-size: 11px; padding: 3px 12px; }
#phone[data-theme="dark"] .packet .pbottom { background: #2f2f32; }

.narration { margin: 12px 4px; background: var(--card); border-radius: 12px; padding: 12px 14px; box-shadow: 0 1px 4px rgba(0,0,0,0.05); }
.narration.me { background: color-mix(in srgb, var(--card) 85%, var(--accent)); margin-left: 40px; }
.narration .who { font-size: 12px; color: var(--sub); margin-bottom: 4px; }
.narration .body { font-size: 15px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }

.versions { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--sub); margin: -4px 0 6px 52px; }
.versions button { font-size: 18px; padding: 0 6px; color: var(--sub); }
.versions button:disabled { opacity: 0.3; }

.quote-bar { display: flex; align-items: center; gap: 8px; background: var(--input-bg); padding: 6px 12px 0; font-size: 12px; color: var(--sub); }
.quote-bar span { flex: 1; background: var(--card); border-radius: 4px; padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inputbar { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px; background: var(--input-bg); border-top: 1px solid var(--line); padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
.inputbar textarea { flex: 1; resize: none; border: none; border-radius: 6px; padding: 9px 10px; font-size: 15px; max-height: 110px; background: var(--card); outline: none; line-height: 1.4; }
.inputbar button { height: 38px; border-radius: 6px; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.icon-btn { font-size: 24px !important; width: 34px; font-weight: 400 !important; color: var(--sub); }
.send-btn { background: #07c160; color: #fff; padding: 0 14px; }
.panel { background: var(--input-bg); border-top: 1px solid var(--line); padding: 14px 10px calc(14px + env(safe-area-inset-bottom, 0px)); display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 6px; }
.panel button { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--sub); }
.panel button span { width: 56px; height: 56px; border-radius: 14px; background: var(--card); display: flex; align-items: center; justify-content: center; font-size: 26px; }
.sticker-panel { display: block; max-height: 240px; overflow-y: auto; }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sticker-grid .st, .sticker-grid .st-add { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--sub); }
.sticker-grid img { width: 64px; height: 64px; object-fit: contain; border-radius: 6px; background: var(--card); }
.sticker-grid .st-add { width: 64px; height: 64px; border-radius: 6px; border: 2px dashed var(--line); font-size: 26px; justify-content: center; margin: 0 auto; }
.sticker-grid .st span { max-width: 70px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sticker-hint { font-size: 12px; color: var(--sub); line-height: 1.6; margin-top: 10px; }

/* ===== 表单 ===== */
.form { padding: 14px; }
.group { background: var(--card); border-radius: 12px; padding: 4px 14px; margin-bottom: 14px; }
.group-title { font-size: 13px; color: var(--sub); margin: 6px 4px 6px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.field { padding: 10px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: none; }
.field > label:not(.switch-row) { display: block; font-size: 13px; color: var(--sub); margin-bottom: 5px; }
.field input:not([type=checkbox]):not([type=color]):not([type=range]), .field textarea, .field select { width: 100%; border: none; outline: none; font-size: 15px; resize: vertical; }
.field textarea { min-height: 70px; line-height: 1.55; }
.field .btn.small { margin-top: 6px; }
.hint { font-size: 12px; color: var(--sub); margin-top: 4px; line-height: 1.55; }
.note-text { font-size: 12px; color: var(--sub); line-height: 1.6; margin: -4px 6px 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.switch-row { display: flex !important; justify-content: space-between; align-items: center; gap: 12px; font-size: 15px; color: var(--text) !important; cursor: pointer; }
.switch-row .sub { color: var(--sub); font-size: 13px; }
.mini-num { width: 56px !important; border: 1px solid var(--line) !important; border-radius: 6px; padding: 2px 6px; text-align: center; }
.color-pick { width: 44px; height: 28px; border: none; background: none; cursor: pointer; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.check-row:last-child { border-bottom: none; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.check-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--sub); margin: -4px 6px 12px; }

input[type=checkbox].switch { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 14px; background: #d6d1cc; position: relative; cursor: pointer; transition: background 0.2s; flex-shrink: 0; }
input[type=checkbox].switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: left 0.2s; }
input[type=checkbox].switch:checked { background: #34c759; }
input[type=checkbox].switch:checked::after { left: 20px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.btn { display: block; width: 100%; padding: 12px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; margin-bottom: 10px; }
.btn:active { filter: brightness(0.92); }
.btn.ghost { background: var(--card); color: var(--text); }
.btn.ghost.line { border: 1px solid var(--line); }
.btn.danger { background: var(--card); color: var(--danger); }
.btn.small { display: inline-block; width: auto; padding: 6px 12px; font-size: 13px; margin: 0; border-radius: 8px; white-space: nowrap; flex-shrink: 0; }
.avatar-pick { display: flex; align-items: center; gap: 14px; padding: 12px 0; }
.avatar-pick .avatar { width: 64px; height: 64px; font-size: 26px; border-radius: 12px; }
.status-line { font-size: 13px; padding: 6px 0 2px; line-height: 1.5; }
.status-line.ok { color: #15803d; }
.status-line.bad { color: var(--danger); }

/* 接口列表 */
.api-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.api-row:last-child { border-bottom: none; }
.api-row .meta { flex: 1; min-width: 0; }
.api-row .name { font-size: 15px; font-weight: 500; }
.api-row .sub { font-size: 12px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.api-row .tags { font-size: 11px; color: var(--accent); font-weight: 600; }
.api-row .arrow { color: var(--sub); font-size: 18px; }

/* 记忆 */
.mem-stats { font-size: 13px; color: var(--sub); line-height: 1.7; padding: 4px 6px 12px; }
.mem-item { display: flex; gap: 6px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mem-item:last-child { border-bottom: none; }
.mem-item .txt { flex: 1; font-size: 14px; line-height: 1.55; word-break: break-word; }
.mem-item .txt small { display: block; color: var(--sub); font-size: 11px; margin-top: 2px; font-weight: 400; }
.mem-item button { font-size: 16px; padding: 2px 3px; opacity: 0.45; }
.mem-item button.on { opacity: 1; }
.mem-item.pinned .txt { font-weight: 600; }
.mem-search { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; background: var(--card); outline: none; font-size: 14px; }

/* ===== 弹层 ===== */
.sheet-mask, .form-mask { position: absolute; inset: 0; background: rgba(0,0,0,0.35); z-index: 50; display: none; }
.sheet-mask { align-items: flex-end; }
.form-mask { align-items: center; justify-content: center; padding: 20px; }
.sheet-mask.show, .form-mask.show { display: flex; }
.sheet { width: 100%; background: var(--bg); border-radius: 14px 14px 0 0; padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); max-height: 80%; overflow-y: auto; }
.sheet-title { text-align: center; font-size: 13px; color: var(--sub); padding: 10px 14px 12px; line-height: 1.6; }
.sheet button { display: block; width: 100%; padding: 14px; background: var(--card); font-size: 16px; border-radius: 10px; margin-bottom: 6px; }
.sheet button.danger { color: var(--danger); }
.sheet .cancel { margin-top: 4px; font-weight: 600; }
.form-box { width: 100%; max-width: 340px; background: var(--bg); border-radius: 16px; padding: 16px; max-height: 90%; overflow-y: auto; }
.form-title { font-weight: 600; font-size: 16px; margin-bottom: 8px; line-height: 1.5; }
.form-box .field { background: var(--card); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; border: none; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-actions .btn { margin: 0; }
.img-viewer { position: absolute; inset: 0; background: rgba(0,0,0,0.9); z-index: 70; display: none; align-items: center; justify-content: center; }
.img-viewer.show { display: flex; }
.img-viewer img { max-width: 100%; max-height: 100%; }
.toast { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.78); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 80; opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: 80%; text-align: center; line-height: 1.5; }
.toast.show { opacity: 1; }
