@import url("fonts/fonts.css");
/* 引号用西文字形，避免中文字体里全角引号带来的空隙 */
@font-face { font-family: Q; src: local("Georgia"), local("Times New Roman"); unicode-range: U+2018-201D; }

@property --paper { syntax: '<color>'; inherits: true; initial-value: #1c1712; }
@property --ink { syntax: '<color>'; inherits: true; initial-value: #efe6d6; }
@property --mute { syntax: '<color>'; inherits: true; initial-value: #a8987f; }
@property --accent { syntax: '<color>'; inherits: true; initial-value: #d9893b; }
@property --rule { syntax: '<color>'; inherits: true; initial-value: rgba(239,230,214,.14); }

:root {
  --paper: #1c1712; --ink: #efe6d6; --mute: #a8987f; --faint: rgba(239,230,214,.38);
  --rule: rgba(239,230,214,.14); --accent: #d9893b; --sheet: #241e17; --field: rgba(239,230,214,.06);
  --serif: Q, "Noto Serif SC", "Songti SC", serif;
  --latin: "Instrument Serif", Georgia, serif;
  --sans: -apple-system, "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  --gut: 22px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --kb: 0px;
  color-scheme: dark;
  transition: --paper .7s var(--ease), --ink .7s var(--ease), --mute .7s var(--ease), --accent .7s var(--ease), --rule .7s var(--ease);
}
:root.real {
  --paper: #f3eee5; --ink: #1d1a16; --mute: #7d7262; --faint: rgba(29,26,22,.34);
  --rule: rgba(29,26,22,.13); --accent: #b5452a; --sheet: #fbf8f2; --field: rgba(29,26,22,.05);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--paper); }
body {
  color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased;
  overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
textarea, input { font: inherit; color: inherit; background: none; border: 0; outline: 0; resize: none; }
svg.i { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hidden { display: none !important; }

/* 纸纹：静态，不逐帧变化 */
.grain::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .45; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='.32'/%3E%3C/svg%3E");
}

/* ---------- 主框架 ---------- */
.app { position: relative; z-index: 1; height: calc(100dvh - var(--kb)); display: flex; flex-direction: column; }

.head { padding: calc(env(safe-area-inset-top) + 14px) var(--gut) 12px; position: relative; }
.head::after { content: ""; position: absolute; left: var(--gut); right: var(--gut); bottom: 0; height: 1px; background: var(--rule); }
.folio { display: flex; justify-content: space-between; font: italic 13px/1 var(--latin); color: var(--mute); letter-spacing: .05em; height: 14px; }
.folio .live { display: inline-flex; align-items: center; gap: 6px; }
.folio .live i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: 0; transition: opacity .4s; }
.folio .live.busy i { opacity: 1; animation: blink 1.4s ease-in-out infinite; }
.folio .live.err i { opacity: 1; background: #d2463a; animation: none; }
@keyframes blink { 50% { opacity: .2; } }
.title { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.name { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.name h1 { font: 700 32px/1 var(--serif); letter-spacing: .04em; }
.name em { font: italic 21px/1 var(--latin); color: var(--mute); white-space: nowrap; }
.seal { width: 44px; height: 44px; margin-right: -8px; display: grid; place-items: center; border-radius: 50%; color: var(--accent); transition: transform .35s var(--ease), background .3s; }
.seal:active { transform: scale(.9) rotate(-8deg); background: var(--field); }
.seal svg { width: 30px; height: 30px; }

/* ---------- 聊天区 ---------- */
.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scroll-behavior: auto; }
.chat { min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; padding: 28px var(--gut) 22px; gap: 30px; }
.chat.swap-out { animation: pageOut .32s var(--ease) forwards; }
.chat.swap-in { animation: pageIn .6s var(--ease) both; }
@keyframes pageOut { to { opacity: 0; transform: translateY(-10px); filter: blur(2px); } }
@keyframes pageIn { from { opacity: 0; transform: translateY(14px); } }

.mark { text-align: center; font: italic 14px/1 var(--latin); color: var(--mute); letter-spacing: .08em; display: flex; align-items: center; gap: 12px; justify-content: center; }
.mark::before, .mark::after { content: ""; width: 26px; height: 1px; background: var(--rule); }
.mark.cn { font: 13px/1 var(--sans); letter-spacing: .12em; }
.more { align-self: center; font-size: 13px; color: var(--mute); padding: 10px 16px; border-radius: 999px; border: 1px solid var(--rule); }

.msg { position: relative; transition: transform .25s var(--ease), opacity .25s; }
.msg.enter { animation: rise .55s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.msg.pressing { transform: scale(.985); }
.chat.focusing .msg:not(.focus) { opacity: .28; }

.him p { font: 17px/1.92 var(--serif); margin-bottom: 12px; text-align: justify; text-justify: inter-character; hanging-punctuation: first; word-break: normal; overflow-wrap: anywhere; }
.him p:last-child { margin-bottom: 0; }
.him .act { color: var(--mute); font-size: 15.5px; }
.halt { font-feature-settings: "halt"; }
.him .caret { display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; animation: blink 1s infinite; }
.alts { display: flex; align-items: center; gap: 4px; margin-top: 10px; color: var(--mute); font: italic 14px/1 var(--latin); }
.alts button { width: 36px; height: 32px; display: grid; place-items: center; border-radius: 8px; }
.alts button:disabled { opacity: .25; }
.alts button:active { background: var(--field); }
.err { margin-top: 10px; font-size: 13px; color: #d2463a; display: flex; gap: 12px; align-items: center; }
.err button { text-decoration: underline; text-underline-offset: 3px; }

.me { align-self: flex-end; max-width: 82%; text-align: right; padding-right: 14px; border-right: 2px solid var(--accent); }
.me .t { font-size: 15.5px; line-height: 1.68; white-space: pre-wrap; overflow-wrap: anywhere; }
.me small { display: block; margin-top: 6px; font: 12px/1 var(--sans); letter-spacing: .08em; color: var(--mute); }
.me small.num { font: italic 13px/1 var(--latin); letter-spacing: .02em; }

.event { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: baseline; color: var(--accent); }
.event em { font: italic 26px/1 var(--latin); }
.event span { font-size: 13px; letter-spacing: .04em; }

/* 等待：三枚花豹斑点依次亮起 */
.spots { display: flex; gap: 7px; height: 22px; align-items: center; }
.spots i { width: 9px; height: 7px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spot 1.2s var(--ease) infinite; opacity: .25; }
.spots i:nth-child(2) { animation-delay: .15s; transform: rotate(40deg); }
.spots i:nth-child(3) { animation-delay: .3s; transform: rotate(-30deg); }
.spots em { font: 13px/1 var(--sans); font-style: normal; color: var(--mute); letter-spacing: .12em; margin-left: 6px; animation: rise .5s var(--ease); }
@keyframes spot { 30% { opacity: 1; } 60% { opacity: .25; } }

/* ---------- 底部 ---------- */
.foot { position: relative; padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px); }
.foot::before { content: ""; position: absolute; left: var(--gut); right: var(--gut); top: 0; height: 1px; background: var(--rule); }
.tabs { position: relative; display: flex; gap: 22px; padding: 4px 10px 12px; font-size: 14px; color: var(--mute); }
.tabs button { position: relative; padding: 6px 0; transition: color .4s; min-height: 32px; }
.tabs button.on { color: var(--ink); }
.tabs .bar { position: absolute; bottom: 10px; height: 2px; background: var(--accent); border-radius: 1px; transition: left .5s var(--ease), width .5s var(--ease); }
.input { display: flex; align-items: flex-end; gap: 6px; }
.input textarea { flex: 1; font: 16px/1.6 var(--serif); padding: 10px; max-height: 40vh; min-height: 46px; }
.input textarea::placeholder { color: var(--faint); }
.btn { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none; transition: transform .25s var(--ease), background .3s, color .3s; }
.btn:active { transform: scale(.88); }
.send { background: var(--ink); color: var(--paper); }
.cam { color: var(--mute); width: 42px; margin-right: -4px; }
.cam:active { background: var(--field); }
.attach { display: flex; padding: 2px 10px 10px; }
.attach figure { position: relative; animation: rise .4s var(--ease); }
.attach img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; display: block; box-shadow: 0 0 0 1px var(--rule); }
.attach button { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: var(--paper); display: grid; place-items: center; }
.attach button svg.i { width: 14px; height: 14px; stroke-width: 2.2; }
.me .photo { display: block; margin: 0 0 8px auto; max-width: 100%; width: 220px; max-height: 300px; object-fit: cover; border-radius: 14px; box-shadow: 0 0 0 1px var(--rule); }
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(8,6,4,.94); display: grid; place-items: center; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); animation: pop .3s var(--ease); }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.send:disabled { background: var(--field); color: var(--faint); }
.send .stop { display: none; width: 14px; height: 14px; border-radius: 3px; background: currentColor; }
.send.streaming .arrow { display: none; }
.send.streaming .stop { display: block; }

/* ---------- 底部抽屉 ---------- */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(10,8,6,.42); opacity: 0; transition: opacity .35s; pointer-events: none; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: calc(100dvh - env(safe-area-inset-top) - 28px);
  background: var(--sheet); border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.18);
  transform: translateY(105%); transition: transform .5s var(--ease); display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.on { transform: translateY(0); }
.sheet.dragging { transition: none; }
.grab { padding: 10px 0 4px; display: grid; place-items: center; touch-action: none; }
.grab i { width: 38px; height: 4px; border-radius: 2px; background: var(--rule); }
.sheet header { display: flex; align-items: baseline; justify-content: space-between; padding: 8px var(--gut) 14px; touch-action: none; }
.sheet header h2 { font: 700 22px/1.2 var(--serif); letter-spacing: .03em; }
.sheet header em { font: italic 15px var(--latin); color: var(--mute); margin-left: 8px; }
.sheet header em.cn { font: 13px var(--sans); letter-spacing: .06em; font-style: normal; }
.sheet header button { font-size: 14px; color: var(--accent); padding: 8px 0 8px 12px; }
.sheet .body { overflow-y: auto; padding: 0 var(--gut) 24px; overscroll-behavior: contain; }

.menu { display: grid; gap: 2px; }
.menu button { display: flex; align-items: center; gap: 14px; padding: 15px 2px; text-align: left; border-bottom: 1px solid var(--rule); font-size: 16px; }
.menu button:last-child { border-bottom: 0; }
.menu button small { margin-left: auto; color: var(--mute); font-size: 13px; }
.menu button.danger { color: #d2463a; }

.seg { display: flex; gap: 18px; overflow-x: auto; padding: 0 var(--gut) 12px; margin: 0 calc(var(--gut) * -1) 12px; border-bottom: 1px solid var(--rule); scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { white-space: nowrap; font-size: 14px; color: var(--mute); padding: 6px 0; position: relative; }
.seg button.on { color: var(--ink); }
.seg button.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -13px; height: 2px; background: var(--accent); }

.field { margin-bottom: 22px; }
.field .lab { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 13px; color: var(--mute); letter-spacing: .04em; }
.field .lab button { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; padding: 6px 0 6px 10px; }
.field .lab button.on { color: var(--accent); }
.field .lab svg { width: 15px; height: 15px; }
.field textarea, .field input, .field select {
  width: 100%; background: var(--field); border-radius: 12px; padding: 12px 14px; font: 15px/1.7 var(--serif); color: var(--ink);
  border: 1px solid transparent; transition: border-color .25s; appearance: none;
}
.field input, .field select { font-family: var(--sans); }
.field textarea:focus, .field input:focus { border-color: var(--accent); }
.field .hint { font-size: 12.5px; color: var(--mute); margin-top: 6px; line-height: 1.6; }
.field.locked textarea { opacity: .7; }
.field textarea { min-height: 52px; overflow: hidden; }

.card { padding: 14px 0; border-bottom: 1px solid var(--rule); }
.card h4 { display: flex; justify-content: space-between; align-items: baseline; font: italic 15px var(--latin); color: var(--accent); margin-bottom: 6px; }
.card h4 span { font: 12px var(--sans); color: var(--mute); }
.card p { font: 14.5px/1.85 var(--serif); }
.card textarea { width: 100%; font: 14.5px/1.85 var(--serif); background: var(--field); border-radius: 10px; padding: 10px 12px; }
.thread { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--rule); font: 15px/1.7 var(--serif); }
.thread button { width: 22px; height: 22px; border-radius: 50%; border: 1.6px solid var(--accent); flex: none; margin-top: 3px; display: grid; place-items: center; }
.thread.done { color: var(--mute); text-decoration: line-through; text-decoration-color: var(--rule); }
.thread.done button { background: var(--accent); }
.thread input { flex: 1; font: 15px/1.7 var(--serif); }

.report .row { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--rule); font-size: 14px; }
.report .row span:last-child { font: italic 15px var(--latin); color: var(--mute); }
.report .row.cut { color: var(--mute); text-decoration: line-through; }
.report .meter { height: 6px; border-radius: 3px; background: var(--field); overflow: hidden; margin: 6px 0 18px; }
.report .meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.report .note { font-size: 13px; color: var(--mute); line-height: 1.7; }

.primary { width: 100%; height: 52px; border-radius: 26px; background: var(--ink); color: var(--paper); font-size: 16px; font-weight: 500; transition: transform .2s; }
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .35; }
.ghost { width: 100%; height: 48px; border-radius: 24px; border: 1px solid var(--rule); font-size: 15px; margin-top: 10px; }

.howto .lede { font: 15px/1.85 var(--serif); color: var(--mute); margin-bottom: 22px; }
.howto .pair { display: grid; gap: 0; margin-bottom: 26px; }
.howto ol { list-style: none; display: grid; gap: 0; margin-bottom: 18px; }
.howto li { display: grid; grid-template-columns: 30px 1fr; gap: 8px; padding: 13px 0; border-bottom: 1px solid var(--rule); font-size: 15px; line-height: 1.75; }
.howto li b { font: italic 22px/1.1 var(--latin); color: var(--accent); }
.howto li em { font-style: normal; color: var(--ink); font-weight: 600; margin: 0 3px; }

/* 长按菜单 */
.pop { position: fixed; z-index: 30; min-width: 168px; background: var(--sheet); border-radius: 14px; box-shadow: 0 14px 40px rgba(0,0,0,.28); overflow: hidden; transform-origin: top left; animation: pop .28s var(--ease); }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }
.pop button { display: flex; width: 100%; align-items: center; gap: 12px; padding: 13px 16px; font-size: 15px; border-bottom: 1px solid var(--rule); }
.pop button:last-child { border-bottom: 0; }
.pop button.danger { color: #d2463a; }
.pop svg.i { width: 18px; height: 18px; }

/* 提示条 */
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); z-index: 40; transform: translate(-50%, -20px); opacity: 0; visibility: hidden; transition: transform .5s var(--ease), opacity .3s, visibility 0s .5s; background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 14px; max-width: calc(100% - 40px); text-align: center; }
.toast.on { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition: transform .5s var(--ease), opacity .3s; }

/* ---------- 首次启动 ---------- */
.welcome { position: fixed; inset: 0; z-index: 10; background: var(--paper); overflow-y: auto; padding: calc(env(safe-area-inset-top) + 56px) var(--gut) calc(env(safe-area-inset-bottom) + 28px); display: flex; flex-direction: column; }
.welcome .kicker { font: italic 15px var(--latin); color: var(--mute); letter-spacing: .06em; }
.welcome h1 { font: 700 44px/1.15 var(--serif); margin: 14px 0 18px; letter-spacing: .03em; }
.welcome .lede { font: 16px/1.9 var(--serif); color: var(--mute); margin-bottom: 34px; }
.welcome .quote { font: italic 19px/1.4 var(--latin); color: var(--accent); margin-bottom: 40px; }
.step { display: grid; grid-template-columns: 34px 1fr; gap: 6px 10px; margin-bottom: 26px; }
.step > b { font: italic 26px/1 var(--latin); color: var(--accent); }
.step h3 { font: 600 17px/1.4 var(--serif); }
.step .c { grid-column: 2; }
.step.dim { opacity: .4; pointer-events: none; }
.pick { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; border: 1px dashed var(--rule); margin-top: 10px; font-size: 14.5px; width: 100%; text-align: left; }
.pick.ok { border-style: solid; border-color: var(--accent); }
.pick small { margin-left: auto; color: var(--mute); }
.or { font-size: 12.5px; color: var(--mute); margin: 8px 0 0; }
.or button { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
@media (min-width: 640px) { .app { max-width: 560px; margin: 0 auto; } :root { --gut: 28px; } }
