/* 外壳和子页共用的样式：底子、登录、抽屉、子页顶栏、分组列表、开关词、底部卡片。
   值都取自 tokens.css，规则见 docs/design/设计体系.md。各页自己的样式在 pages/*.css。 */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
/* 整页锁死：只让页面里的列表自己滚，手指拖不动整个页面，也没有橡皮筋回弹 */
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); color: var(--ink); font: 400 13px/1.6 var(--sans); font-synthesis: none; -webkit-text-size-adjust: 100%; }
html, body { touch-action: pan-x pan-y; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* 登录：只有一个密码框，标题和子页同一种衬线 */
.login { min-height: 100%; display: grid; place-items: center; padding: var(--page-x); }
.login form { width: min(320px, 100%); display: flex; flex-direction: column; gap: var(--gap-in); }
.login .t-title { text-align: center; margin-bottom: var(--gap-section); }
.login input { height: var(--input-h); padding: 0 12px; border: 0; border-radius: var(--r-input); background: var(--chip); font-size: 15px; outline: none; }
.login input:focus { box-shadow: 0 0 0 1px var(--ring); }

/* 外壳：抽屉在下，当前页是一张卡片；抽屉打开时卡片推到右边，不盖住 */
/* 外壳跟着手机实际可见的区域走（--vv-top／--vv-h 由 viewport.js 按 visualViewport 设）：键盘弹起时整页缩到键盘上方，输入框贴着键盘 */
.app { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vv-h, 100%); overflow: hidden; background: var(--bg); }
.drawer { position: absolute; inset: 0 auto 0 0; width: 73%; padding: calc(72px + env(safe-area-inset-top)) 18px calc(34px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 4px; }
.who { display: flex; align-items: center; gap: 12px; padding: 0 10px 26px; }
.who .avatar { width: 48px; height: 48px; border-radius: 50%; flex: none; background: var(--chip) var(--user-avatar-image, none) center / cover; }
.who-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who-name b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-name .edit { width: 28px; height: 36px; }
.profile-status { margin: -16px 12px 12px; }
.profile-form { display: grid; gap: var(--gap-in); }
.who b { font: var(--chat-font-name); color: var(--ink); }
.drawer a { display: flex; align-items: center; gap: 16px; height: 52px; padding: 0 12px; border-radius: 16px; font: var(--chat-font-nav); color: var(--ink); text-decoration: none; transition: transform var(--dur-press) var(--chat-ease), background var(--dur-press); }
.drawer a svg { width: 22px; height: 22px; flex: none; }
.drawer a[aria-current="page"] { background: var(--chip); }
.drawer a:active { transform: scale(var(--chat-press-scale)); background: var(--chat-press-bg); }
.dedication { margin: auto 12px 0; font: var(--chat-font-dedication); color: var(--muted); }
/* 抽屉打开时入口依次淡入 */
.app.open .drawer > * { animation: drawer-in var(--chat-dur-push) var(--chat-ease) backwards; }
.app.open .drawer > :nth-child(2) { animation-delay: 30ms; } .app.open .drawer > :nth-child(3) { animation-delay: 60ms; }
.app.open .drawer > :nth-child(4) { animation-delay: 90ms; } .app.open .drawer > :nth-child(5) { animation-delay: 120ms; }
.app.open .drawer > :nth-child(6) { animation-delay: 150ms; } .app.open .drawer > :nth-child(7) { animation-delay: 180ms; }
@keyframes drawer-in { from { opacity: 0; transform: translateX(-8px); } }

.card { position: absolute; inset: 0; background: var(--bg); display: flex; flex-direction: column; transition: transform var(--chat-dur-push) var(--chat-ease), border-radius var(--chat-dur-push) var(--chat-ease), box-shadow var(--chat-dur-push); }
.app.open .card { transform: translateX(73%); border-radius: var(--chat-r-push) 0 0 var(--chat-r-push); box-shadow: var(--chat-shadow-push); overflow: hidden; }
.card-shade { position: absolute; inset: 0; z-index: 30; width: 100%; background: rgb(250 250 250 / .62); border-radius: inherit; }
.view { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* 子页顶栏：左返回、中间衬线标题、右边一个图标，都 40 高同一中线 */
.sub-header { display: grid; grid-template-columns: var(--icon-btn) 1fr var(--icon-btn); align-items: center; padding: var(--header-pad); padding-top: calc(35px + env(safe-area-inset-top)); min-height: calc(var(--header-h) + env(safe-area-inset-top)); flex: none; }
.sub-header .t-title { line-height: 1; text-align: center; }
.icon { width: var(--icon-btn); height: var(--icon-btn); display: grid; place-items: center; border-radius: 50%; color: var(--ink); }
.icon svg { width: 20px; height: 20px; }
.icon:active { background: var(--chip); }
.sub-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
.sub-scroll::-webkit-scrollbar { display: none; }

/* 分组列表：板块之间 24；板块名下一条细线；项与项、板块名与第一项都是细线两边各 12 */
.group { padding: var(--gap-section) var(--page-x) 0; }
.group:last-child { padding-bottom: max(var(--gap-section), env(safe-area-inset-bottom)); }
.group-head { margin: 0; padding: 0 0 var(--gap-row); border-bottom: 1px solid var(--line); font: 400 12px/20px var(--sans); letter-spacing: var(--track); color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; padding: var(--gap-row) 0; border-bottom: 1px solid var(--line); text-align: left; }
button.row:active { background: var(--chip); }
.row-main { min-width: 0; display: flex; flex-direction: column; }
.row-main .t-desc { overflow-wrap: anywhere; }

/* 右侧控件右缘对齐：修改用小铅笔 */
.edit { flex: none; display: grid; place-items: center; height: 24px; margin-right: -2px; color: var(--ink); }
.edit svg { width: 15px; height: 15px; }

/* ON／OFF 开关词：定宽、圆点左对齐，点按区 36 但不撑高行；减掉末尾字距让 OFF 右缘对齐 */
.word { flex: none; width: var(--word-w); height: var(--hit); margin: -6px calc(-1 * var(--track)) -6px 0; display: inline-flex; align-items: center; gap: 8px; font: 400 12px/1 var(--sans); letter-spacing: var(--track); color: var(--ink); }
.word i { width: var(--dot); height: var(--dot); flex: none; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 var(--dot-ring) var(--chip); transition: background var(--dur-fade), box-shadow var(--dur-fade); }
.word[aria-pressed="false"] { color: var(--muted); }
.word[aria-pressed="false"] i { background: transparent; box-shadow: inset 0 0 0 1.2px var(--dim); }
.word:active { opacity: var(--press-fade); }

/* 文字按钮与主按钮 */
.text-btn { flex: none; height: var(--hit); font: 400 13px/1 var(--sans); color: var(--ink); }
.text-btn:active { opacity: var(--press-fade); }
.text-btn:disabled { color: var(--muted); cursor: default; }
.primary { height: var(--input-h); border-radius: calc(var(--input-h) / 2); background: var(--primary); color: var(--surface); font: 400 15px/1 var(--sans); transition: transform var(--dur-press) var(--ease); }
.primary:active { transform: scale(var(--press-scale)); }

/* 底部卡片 */
.sheet-wrap { position: fixed; top: var(--vv-top, 0px); left: 0; right: 0; height: var(--vv-h, 100%); z-index: 50; display: flex; align-items: flex-end; background: var(--scrim); }
.sheet { width: 100%; max-height: calc(100% - var(--sheet-top)); display: flex; flex-direction: column; overflow: hidden; background: var(--bg); border-radius: var(--r-sheet) var(--r-sheet) 0 0; box-shadow: var(--shadow-sheet); animation: sheet-up var(--dur-sheet) var(--ease); }
.sheet-head { position: relative; padding: var(--sheet-pad-top) var(--page-x) 0; flex: none; }
.sheet-head .t-title { outline: none; overflow-wrap: anywhere; }
.handle { position: absolute; top: 0; left: calc(50% - 32px); width: 64px; height: 30px; display: grid; place-items: center; }
.handle::after { content: ""; width: var(--handle-w); height: var(--handle-h); border-radius: var(--handle-h); background: var(--handle); }
.sheet-body { display: flex; flex-direction: column; gap: var(--gap-in); padding: 16px var(--page-x) max(var(--gap-section), env(safe-area-inset-bottom)); overflow: auto; min-height: 0; }
.sheet-body label { display: flex; flex-direction: column; gap: var(--gap-in); font: 400 12px/20px var(--sans); letter-spacing: var(--track); color: var(--muted); }
.sheet-body input, .sheet-body textarea { letter-spacing: 0; padding: 0 12px; border: 0; border-radius: var(--r-input); background: var(--chip); font: 400 15px/24px var(--sans); color: var(--ink); outline: none; }
.sheet-body input { height: var(--input-h); }
.sheet-body textarea { padding: 12px; resize: none; }
.sheet-body input:focus, .sheet-body textarea:focus { box-shadow: 0 0 0 1px var(--ring); }
.sheet-body input[aria-invalid="true"] { box-shadow: 0 0 0 1px var(--ink); }
@keyframes sheet-up { from { transform: translateY(30px); opacity: .4; } }
/* 收起：卡片往下沉、遮罩淡掉（ui.js 的 hideOut 等播完再移除） */
.sheet-wrap { animation: fade-in var(--dur-fade) var(--ease); }
.sheet-wrap.out { animation: fade-out var(--dur-sheet) var(--ease) forwards; pointer-events: none; }
.sheet-wrap.out .sheet { animation: sheet-down var(--dur-sheet) var(--ease) forwards; }
@keyframes sheet-down { to { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* 换页：去子页从右边滑进来，回聊天从左边滑回来（app.js 的 route 加 .enter-r／.enter-l） */
.view.enter-r { animation: page-in-r var(--chat-dur-push) var(--chat-ease) backwards; }
.view.enter-l { animation: page-in-l var(--chat-dur-push) var(--chat-ease) backwards; }
@keyframes page-in-r { from { opacity: 0; transform: translateX(28px); } }
@keyframes page-in-l { from { opacity: 0; transform: translateX(-28px); } }

/* 真手机上照草图窄屏的顶栏：上面只留 10，整条高 60（都另加刘海的安全区） */
@media (max-width: 460px) {
  .sub-header { padding-top: calc(10px + env(safe-area-inset-top)); padding-bottom: 10px; min-height: calc(60px + env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* iPhone 聚焦小字号输入框会自动放大，所有文本控件统一防止触发。 */
@media (pointer: coarse) { input, textarea, select { font-size: 16px !important; } }

/* Live 胶囊：开着的角色。圆点慢慢呼吸；从 Wake 变成 Live 时胶囊底色和圆点一起过渡，Waking 时圆点转圈似的闪 */
.live-pill { display: inline-flex; align-items: center; gap: 7px; height: var(--hit); padding: 0 14px; border-radius: 18px; background: var(--chip); font: 400 13px/1 var(--sans); letter-spacing: .02em; color: var(--muted); transition: background 320ms var(--chat-ease), color 320ms var(--chat-ease), transform var(--dur-press) var(--chat-ease); }
.live-pill b { font-weight: inherit; }
.live-pill i { width: 7px; height: 7px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1.3px currentColor; transition: background 320ms, box-shadow 320ms; }
.live-pill.on { background: var(--ink); color: var(--surface); }
.live-pill.on i { background: #7bd88f; box-shadow: 0 0 0 0 rgb(123 216 143 / .6); animation: live-breathe 2.4s ease-in-out infinite; }
.live-pill.waking i { animation: live-blink .7s ease-in-out infinite; }
.live-pill.small { height: 24px; padding: 0 10px; font-size: 11px; flex: none; }
.live-pill.small i { width: 6px; height: 6px; }
@keyframes live-breathe { 50% { box-shadow: 0 0 0 4px rgb(123 216 143 / 0); } 0%, 100% { box-shadow: 0 0 0 0 rgb(123 216 143 / .55); } }
@keyframes live-blink { 50% { opacity: .25; } }
