/* 书林智友 · 公用组件 */

/* 顶栏 */
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    background: rgba(246, 238, 223, .82);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; text-align: center; min-width: 0; }
.topbar-title b { font-family: var(--serif); font-size: 19px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title small { display: block; font-size: 12px; color: var(--ink-3); line-height: 1.2; }
.topbar-right { display: flex; gap: 4px; }
.topbar.clear { background: transparent; border-bottom: none; backdrop-filter: none; -webkit-backdrop-filter: none; position: absolute; left: 0; right: 0; }
.topbar.clear .icon-btn { background: rgba(255, 250, 240, .85); box-shadow: var(--shadow); }

/* 底部导航 */
.tabbar {
    position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: min(520px, calc(100% - 24px)); height: var(--tab-h);
    display: grid; grid-template-columns: repeat(4, 1fr);
    background: rgba(255, 250, 240, .9);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, .7); border-radius: 22px; box-shadow: var(--shadow-lg);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--ink-3); position: relative; transition: color .2s; }
.tab .ic { width: 24px; height: 24px; transition: transform .3s var(--ease); }
.tab.on { color: var(--cinnabar); font-weight: 700; }
.tab.on .ic { transform: translateY(-2px) scale(1.08); }
.tab.on::after { content: ""; position: absolute; bottom: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--cinnabar); }

/* 头像 */
.avatar { border-radius: 50%; object-fit: cover; background: var(--paper-2); border: 3px solid #fffaf0; box-shadow: 0 4px 14px rgba(74, 52, 30, .2); }
.av-sm { width: 40px; height: 40px; border-width: 2px; }
.av-md { width: 64px; height: 64px; }
.av-lg { width: 96px; height: 96px; }
.av-xl { width: 140px; height: 140px; border-width: 4px; }
.me-dot { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--gold), #a87d2a); color: #fff; font-family: var(--serif); font-size: 18px; flex-shrink: 0; box-shadow: 0 4px 12px rgba(199, 154, 58, .35); }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; z-index: 200; background: rgba(40, 28, 18, .45); display: grid; place-items: center; padding: 20px; animation: fade .25s both; }
.modal-mask.out { animation: fadeOut .25s both; }
.modal { width: min(440px, 100%); max-height: 86vh; overflow: auto; padding: 24px 22px 18px; animation: pop .35s var(--ease) both; }
.modal-title { font-family: var(--serif); font-size: 22px; margin-bottom: 12px; text-align: center; }
.modal-body { color: var(--ink-2); }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.modal-actions .btn { min-width: 110px; }
@keyframes fade { from { opacity: 0; } } @keyframes fadeOut { to { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.9) translateY(10px); } }

/* 提示条 */
#toast { position: fixed; top: calc(70px + env(safe-area-inset-top)); left: 0; right: 0; z-index: 300; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast-item { background: rgba(59, 47, 37, .92); color: #fff8ee; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); animation: pop .3s var(--ease) both; }
.toast-item.out { animation: fadeOut .4s both; }

/* 撒花 */
.confetti { position: fixed; top: -12px; width: 9px; height: 14px; z-index: 400; border-radius: 2px; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .8; } }

/* 打字中 */
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.cursor::after { content: "▍"; color: var(--gold); animation: caret 1s steps(1) infinite; margin-left: 1px; }
@keyframes caret { 50% { opacity: 0; } }

/* AI 文本排版 */
.md h4 { font-family: var(--serif); font-size: 17px; margin: 14px 0 6px; color: var(--cinnabar); }
.md h4:first-child { margin-top: 0; }
.md p { margin: 6px 0; }
.md ul, .md ol { padding-left: 1.3em; margin: 6px 0; }
.md li { margin: 3px 0; }
.md b { color: var(--ink); }

/* 进度条 */
.bar { height: 10px; border-radius: 999px; background: var(--paper-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--cinnabar-2)); width: 0; transition: width 1s var(--ease); }

/* 空状态 */
.empty { text-align: center; padding: 34px 16px; color: var(--ink-3); }
.empty img { width: 120px; margin: 0 auto 10px; border-radius: 50%; opacity: .9; }

/* 书童气泡 */
.mascot-say { display: flex; align-items: flex-end; gap: 10px; }
.mascot-say img { width: 74px; height: 74px; border-radius: 50%; object-fit: cover; object-position: center 20%; border: 3px solid #fffaf0; box-shadow: var(--shadow); flex-shrink: 0; animation: float 4s ease-in-out infinite; }
.mascot-say .say { position: relative; padding: 12px 15px; font-size: 15px; border-radius: 16px 16px 16px 4px; }
@keyframes float { 50% { transform: translateY(-6px); } }

/* 分段切换 */
.seg { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg .chip { white-space: nowrap; padding: 7px 14px; font-size: 14px; }
