:root {
  --ink: #14110F;
  --ink-deep: #0B0908;
  --surface: #1F1B19;
  --surface-2: #2A2522;
  --line: #3A332F;
  --text: #F5EFEA;
  --text-2: #CFC8C3;
  --muted: #A8A29E;
  --thread: #C8323C;
  --thread-text: #F2707A;
  --thread-dim: #6B2A30;
  --ok: #7BC99B;
  --warn: #E8B45A;
  --sans: 'Noto Sans SC', system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --serif: 'Noto Serif SC', 'Songti SC', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink-deep); color: var(--text); font-family: var(--sans); }
body { display: flex; justify-content: center; }
a { color: var(--thread-text); }
button, input, select, textarea { font-family: inherit; font-size: 15px; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--thread-text); outline-offset: 2px; }

#app { width: 100%; max-width: 480px; min-height: 100dvh; background: var(--ink); display: flex; flex-direction: column; position: relative; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.serif { font-family: var(--serif); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex-grow: 1; }
.page { padding: 20px; display: flex; flex-direction: column; gap: 16px; flex-grow: 1; overflow-y: auto; padding-bottom: 88px; }

.btn { height: 48px; border-radius: 24px; border: 1px solid var(--line); background: transparent; color: var(--text); padding: 0 18px; }
.btn.primary { background: var(--thread); border-color: var(--thread); color: #fff; font-weight: 700; }
.btn.small { height: 34px; border-radius: 17px; font-size: 13px; padding: 0 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.pill { height: 26px; padding: 0 10px; border-radius: 13px; background: var(--surface); border: 1px solid var(--line); font-size: 12px; display: inline-flex; align-items: center; }
.card { background: var(--surface); border-radius: 16px; padding: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field textarea, .field select { height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--ink); color: var(--text); padding: 0 14px; }
.field textarea { height: 80px; padding: 10px 14px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; line-height: 1.6; color: var(--text-2); }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--thread); flex-shrink: 0; }
.err { color: var(--thread-text); font-size: 13px; min-height: 18px; }

/* login */
.hero { height: 300px; position: relative; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; }
.hero svg { position: absolute; left: -20px; top: 30px; }
.brand { font-family: var(--serif); font-size: 44px; font-weight: 700; }

/* header + nav */
.top { padding: 16px 20px 10px; display: flex; align-items: center; gap: 8px; }
.top .title { font-family: var(--serif); font-size: 22px; font-weight: 700; flex-grow: 1; }
.credits { height: 32px; padding: 0 12px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.tabbar { position: fixed; bottom: 0; width: 100%; max-width: 480px; height: 64px; background: var(--ink); border-top: 1px solid var(--surface-2); display: grid; grid-template-columns: repeat(4, 1fr); z-index: 5; }
.tabbar a { color: var(--muted); text-decoration: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; }
.tabbar a.on { color: var(--thread-text); }

/* gallery */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.pcard { display: flex; flex-direction: column; text-decoration: none; color: var(--text); background: var(--surface); border-radius: 14px; overflow: hidden; }
.pcard .img { aspect-ratio: 3/4; background: var(--surface-2) center/cover no-repeat; position: relative; }
.pcard .badges { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; justify-content: space-between; }
.badge { height: 22px; padding: 0 8px; border-radius: 11px; background: var(--ink); font-size: 11px; display: inline-flex; align-items: center; color: var(--text-2); }
.badge.thread { color: var(--thread-text); }
.pcard .meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.pcard .name { font-size: 15px; font-weight: 700; }
.pcard .line { font-size: 12px; color: var(--muted); }

/* thread progress */
.thread-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.thread-bar span { height: 6px; border-radius: 3px; background: var(--line); }
.thread-bar span.done { background: var(--thread); }
.thread-bar span.part { background: var(--thread-dim); }

/* detail */
.portrait { aspect-ratio: 3/4; max-height: 380px; width: 100%; background: var(--surface-2) center/cover no-repeat; position: relative; }
.back { position: absolute; top: 14px; left: 14px; width: 44px; height: 44px; border-radius: 22px; background: var(--ink); color: var(--text); display: flex; align-items: center; justify-content: center; border: none; text-decoration: none; }

/* chat */
.chat { display: flex; flex-direction: column; height: 100dvh; }
.chat-head { padding: 10px 10px 8px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--surface-2); }
.chat-head .back { position: static; background: transparent; }
.avatar { width: 40px; height: 40px; border-radius: 20px; background: var(--surface-2) center/cover; flex-shrink: 0; }
.chat-head .small { white-space: nowrap; }
.mini-bar { width: 72px; flex-shrink: 0; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.mini-bar i { display: block; height: 4px; background: var(--thread); }
.stream { flex-grow: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.stream > * { flex-shrink: 0; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--thread); color: #fff; border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 4px; }
.photo { align-self: flex-start; width: 210px; border-radius: 16px; overflow: hidden; background: var(--surface-2); position: relative; border: none; padding: 0; color: var(--text); text-align: left; }
.photo img { width: 100%; display: block; aspect-ratio: 3/4; object-fit: cover; }
.photo.blur img { filter: blur(22px); }
.photo .cap { padding: 8px 10px; font-size: 12px; color: var(--text-2); }
.photo .reveal { position: absolute; inset: 0 0 34px 0; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.system { align-self: center; font-size: 12px; color: var(--muted); text-align: center; padding: 4px 10px; }
.system.thread { color: var(--thread-text); }
.typing { align-self: flex-start; background: var(--surface); border-radius: 18px; padding: 12px 16px; display: flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 3px; background: var(--muted); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
.quick { padding: 6px 12px; display: flex; gap: 8px; overflow-x: auto; }
.quick .btn { white-space: nowrap; }
.composer { padding: 8px 12px 16px; display: flex; gap: 8px; }
.composer input { flex-grow: 1; height: 46px; border-radius: 23px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 0 16px; }
.send { width: 46px; height: 46px; border-radius: 23px; border: none; background: var(--thread); color: #fff; display: flex; align-items: center; justify-content: center; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(11, 9, 8, .72); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { width: 100%; max-width: 480px; background: var(--surface); border-radius: 24px 24px 0 0; padding: 14px 24px 28px; display: flex; flex-direction: column; gap: 16px; }
.sheet .grab { align-self: center; width: 40px; height: 4px; border-radius: 2px; background: var(--line); }
.toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 10px 16px; font-size: 13px; z-index: 30; max-width: 90%; }

/* lists */
.list { background: var(--surface); border-radius: 16px; padding: 4px 16px; }
.list > * { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--surface-2); font-size: 14px; }
.list > *:last-child { border-bottom: none; }
.list input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--thread); }
.list select { height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--ink); color: var(--text); padding: 0 10px; }
.danger { color: var(--thread-text); }
