:root {
  --bg: #fbf7f2;
  --panel: #ffffff;
  --text: #2b2620;
  --muted: #8a8178;
  --line: rgba(0, 0, 0, 0.08);
  --chip: #f1eae1;
  --accent: #e07a32;
  --me: #e07a32;
  --danger: #c9433d;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --panel: #23252b;
    --text: #eee9e3;
    --muted: #9a948c;
    --line: rgba(255, 255, 255, 0.08);
    --chip: #2c2e35;
    --accent: #ef8f4a;
    --me: #b8612a;
    --danger: #ef6b64;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button { font-family: inherit; cursor: pointer; touch-action: manipulation; color: inherit; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 560px; margin: 0 auto; }

.top { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 8px) 14px 6px; }
.avatar { width: 38px; height: 38px; flex: none; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 17px; }
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.who { flex: 1; min-width: 0; }
.name { font-size: 17px; font-weight: 600; }
.sub { font-size: 12px; color: var(--muted); }
.icon-btn { border: none; background: transparent; padding: 6px; color: var(--muted); }

.contexts, .quick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.contexts::-webkit-scrollbar, .quick::-webkit-scrollbar { display: none; }
.contexts { padding: 2px 14px 8px; border-bottom: 1px solid var(--line); }
.ctx-label { font-size: 12px; color: var(--muted); align-self: center; white-space: nowrap; margin-right: 2px; }
.chip { border: none; background: var(--chip); border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.chip.on, .chip.ok { background: var(--accent); color: #fff; }
.chip.ghost { background: transparent; color: var(--muted); padding-left: 6px; padding-right: 6px; }

.chat { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 8px; align-items: flex-end; }
.msg .bubble { padding: 10px 12px; max-width: 82%; }
.msg.cat .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; }
.msg.me { justify-content: flex-end; }
.msg.me .bubble { background: var(--me); color: #fff; border-radius: 16px 16px 4px 16px; max-width: 78%; }
.msg.sys { justify-content: center; }
.msg.sys span { font-size: 12px; color: var(--muted); background: var(--chip); padding: 7px 11px; border-radius: 10px; max-width: 92%; line-height: 1.6; }
.line { font-size: 17px; line-height: 1.45; margin: 6px 0 4px; word-break: break-word; }
.msg.me .line { margin-top: 0; }
.meta { font-size: 13px; color: var(--muted); line-height: 1.5; }
.meta b { color: var(--text); font-weight: 600; }
.msg.me .meta { color: rgba(255, 255, 255, 0.85); }
.note { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.msg.me .note { color: rgba(255, 255, 255, 0.9); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.actions .chip { padding: 4px 12px; font-size: 13px; }
.labeled { font-size: 12px; color: var(--muted); }
.audio-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.play { width: 28px; height: 28px; flex: none; border-radius: 50%; border: none; background: var(--accent); color: #fff; display: grid; place-items: center; padding: 0; }
.play .ic { display: grid; place-items: center; margin-left: 2px; }
.tag { background: var(--chip); color: var(--text); padding: 2px 8px; border-radius: 6px; }
.tag.soft { color: var(--muted); }
.debug { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--muted); margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line); line-height: 1.55; white-space: pre-wrap; }

.bottom { padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px); border-top: 1px solid var(--line); background: var(--bg); }
.quick { padding-bottom: 8px; }
.composer { display: flex; gap: 8px; margin: 0 0 8px; }
#input { flex: 1; min-width: 0; font-size: 16px; padding: 10px 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel); color: var(--text); outline: none; }
#btnSend { border: none; background: var(--accent); color: #fff; border-radius: 22px; padding: 0 18px; font-size: 15px; }
.hold { width: 100%; height: 56px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); font-size: 17px; font-weight: 600; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; transition: transform 0.08s; }
.hold.active { background: var(--accent); color: #fff; border-color: transparent; transform: scale(0.98); }
.rec { display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 8px; border-radius: 12px; background: var(--chip); font-size: 14px; font-variant-numeric: tabular-nums; }
.rec .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.level { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.level i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.08s; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-end; z-index: 10; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; margin: 0 auto; max-height: 90vh; max-height: 90dvh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 18px); }
.sheet h2 { font-size: 18px; margin: 0 0 8px; }
.sheet h3 { font-size: 13px; margin: 20px 0 4px; color: var(--muted); font-weight: 600; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.row input[type="text"] { width: 9em; font-size: 16px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); text-align: right; }
.vol { display: flex; align-items: center; gap: 8px; }
.vol input { width: 120px; accent-color: var(--accent); }
.switch { width: 22px; height: 22px; accent-color: var(--accent); }
.seg { display: flex; gap: 4px; }
.seg button { border: none; background: var(--chip); border-radius: 8px; padding: 6px 10px; font-size: 14px; }
.seg button.on { background: var(--accent); color: #fff; }
.btn { border: none; border-radius: 12px; padding: 10px 14px; background: var(--chip); font-size: 15px; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; margin-top: 12px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.opt { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 12px; font-size: 15px; text-align: left; }
.out { font-size: 12px; color: var(--muted); white-space: pre-wrap; margin-top: 8px; line-height: 1.6; }
.out:empty { display: none; }
.lib-head { font-size: 14px; font-weight: 600; margin: 12px 0 2px; }
.lib-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.lib-text { flex: 1; min-width: 0; }
