/* 王明夫 · 思维克隆体 —— "书院 · 莲":宣纸、墨、朱砂 */

:root {
  --paper: #F4EEE3;
  --paper-2: #EBE3D4;
  --paper-3: #E2D8C5;
  --ink: #1E1A15;
  --ink-2: #463F35;
  --muted: #6E6457;
  --line: rgba(30, 26, 21, .12);
  --seal: #A83A2C;
  --seal-soft: rgba(168, 58, 44, .10);
  --veil: rgba(244, 238, 227, .82);
  --shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 12px 32px -18px rgba(60, 40, 20, .35);
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --gutter: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14120F;
    --paper-2: #1D1A16;
    --paper-3: #27231D;
    --ink: #ECE4D6;
    --ink-2: #CDC2B0;
    --muted: #8E8473;
    --line: rgba(236, 228, 214, .12);
    --seal: #D0614A;
    --seal-soft: rgba(198, 85, 63, .14);
    --veil: rgba(20, 18, 15, .78);
    --shadow: 0 12px 32px -18px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
/* 宣纸纹理:极细的噪点 */
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4  0 0 0 0 .3  0 0 0 0 .2  0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: .9;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* 背景莲 */
.lotus {
  position: fixed; z-index: 0; pointer-events: none;
  width: min(120vw, 620px); right: -22%; bottom: -12%;
  color: var(--ink); opacity: .06;
}

/* ============ 入口页 ============ */
.gate {
  position: relative; z-index: 1;
  min-height: 100svh;
  max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: 0 0 calc(28px + env(safe-area-inset-bottom));
}
.gate-portrait {
  position: relative; margin: 0;
  height: min(51svh, 500px);
  overflow: hidden;
}
.gate-portrait img {
  width: 100%; height: 100%; object-fit: cover; object-position: 52% 12%;
  display: block;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 52%, transparent 98%),
                      linear-gradient(to right, transparent 0%, #000 14%, #000 86%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to bottom, #000 0%, #000 52%, transparent 98%),
              linear-gradient(to right, transparent 0%, #000 14%, #000 86%, transparent 100%);
  mask-composite: intersect;
  filter: saturate(.92) contrast(1.02);
  animation: rise 1.4s cubic-bezier(.2,.7,.2,1) both;
}
@media (prefers-color-scheme: dark) { .gate-portrait img { filter: saturate(.8) brightness(.86) contrast(1.05); } }
@keyframes rise { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }

/* 朱砂印章 */
.seal {
  position: absolute; right: var(--gutter); top: calc(18px + env(safe-area-inset-top));
  display: grid; grid-template-columns: 1fr; gap: 1px;
  padding: 7px 6px; border-radius: 3px;
  background: var(--seal); color: #F6EBDD;
  font-family: var(--serif); font-weight: 600; font-size: 13px; line-height: 1.15;
  box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset;
  opacity: .92; transform: rotate(-2deg);
  animation: fade .9s 1.1s both;
}

.gate-copy {
  margin-top: -30px; padding: 0 var(--gutter); position: relative; text-align: center;
}
.gate-copy > * { animation: fade .9s both; }
.gate-copy > .name { animation-delay: .35s; }
.gate-copy > .role { animation-delay: .5s; }
.gate-copy > .motto { animation-delay: .7s; }
.gate-copy > .gate-form { animation-delay: .9s; }
.gate-copy > .disclaimer { animation-delay: 1.05s; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.name {
  margin: 0; font-family: var(--serif); font-weight: 600;
  font-size: 44px; letter-spacing: .28em; text-indent: .28em; line-height: 1.1;
}
.role { margin: 12px 0 0; color: var(--ink-2); font-size: 13px; letter-spacing: .08em; }
.motto {
  margin: 22px auto 0; padding: 0;
  font-family: var(--serif); font-size: 16px; line-height: 1.95; color: var(--ink-2);
  max-width: 22em; position: relative;
}

.gate-form { margin: 18px auto 0; max-width: 320px; display: grid; gap: 14px; }
.gate-form input {
  width: 100%; height: 52px; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--ink);
  text-align: center; font-size: 17px; letter-spacing: .24em;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  outline: none; transition: border-color .3s;
  border-radius: 0;
}
.gate-form input::placeholder { color: var(--muted); letter-spacing: .12em; font-family: var(--sans); font-size: 15px; }
.gate-form input:focus { border-bottom-color: var(--ink); }
.gate-err { margin: 0; min-height: 1.2em; color: var(--seal); font-size: 13px; }
.disclaimer { margin: 18px auto 0; max-width: 21em; color: var(--muted); font-size: 12px; line-height: 1.75; }

.btn-ink {
  position: relative; height: 50px; border: 0; border-radius: 4px;
  background: var(--ink); color: var(--paper);
  font-family: var(--serif); font-size: 16px; letter-spacing: .3em; text-indent: .3em;
  overflow: hidden; box-shadow: var(--shadow);
  transition: transform .2s ease, opacity .2s;
}
.btn-ink:active { transform: scale(.98); }
.btn-ink[disabled] { opacity: .5; }
.btn-ink span { position: relative; }

/* ============ 对话页 ============ */
.room {
  position: relative; z-index: 1;
  height: 100svh; max-width: 720px; margin: 0 auto;
  display: grid; grid-template-rows: auto 1fr auto;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: var(--veil);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 3;
}
.who { display: flex; align-items: center; gap: 11px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; display: block;
  box-shadow: 0 0 0 1px var(--line), 0 0 0 3px var(--paper), 0 0 0 4px var(--seal-soft); }
.who-name { font-family: var(--serif); font-weight: 600; font-size: 16px; letter-spacing: .12em; }
.who-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.actions { display: flex; gap: 2px; position: relative; }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; border-radius: 50%;
  display: grid; place-items: center; color: var(--ink-2); }
.icon-btn:active { background: var(--paper-2); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.icon-btn svg circle { fill: currentColor; stroke: none; }
.menu {
  position: absolute; right: 0; top: 46px; min-width: 150px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; display: grid;
}
.menu button { text-align: left; border: 0; background: transparent; padding: 11px 12px; border-radius: 8px; font-size: 14px; }
.menu button:active { background: var(--paper-2); }

.thread {
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 18px var(--gutter) 32px;
  scroll-behavior: smooth;
}

/* 欢迎 */
.welcome { text-align: center; padding: 28px 0 8px; animation: fade 1s both; }
.welcome-avatar { width: 72px; height: 72px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 1px var(--line), 0 0 0 5px var(--paper), 0 0 0 6px var(--seal-soft); }
.welcome-hi { font-family: var(--serif); font-size: 22px; font-weight: 600; margin: 18px 0 8px; letter-spacing: .08em; }
.welcome-text { color: var(--ink-2); font-size: 14.5px; line-height: 1.9; max-width: 30em; margin: 0 auto; }
.starters { display: grid; gap: 10px; margin: 26px auto 0; max-width: 520px; }
@media (min-width: 560px) { .starters { grid-template-columns: 1fr 1fr; } }
.starter {
  text-align: left; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px;
  background: color-mix(in srgb, var(--paper-2) 55%, transparent);
  font-family: var(--serif); font-size: 15px; line-height: 1.6; color: var(--ink);
  transition: transform .2s, border-color .2s, background .2s;
}
.starter:active { transform: scale(.985); border-color: var(--seal); }

/* 提问 */
.q { display: flex; justify-content: flex-end; margin: 26px 0 6px; animation: fade .4s both; }
.q-bubble {
  max-width: 82%; padding: 11px 15px; border-radius: 18px 18px 4px 18px;
  background: var(--ink); color: var(--paper);
  font-size: 15.5px; line-height: 1.7; white-space: pre-wrap; word-break: break-word;
}

/* 先生的回答:像一封回信 */
.a { margin: 18px 0 8px; animation: fade .5s both; }
.a-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.a-head img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.a-body { font-family: var(--serif); font-size: 17px; line-height: 2; color: var(--ink); letter-spacing: .01em; }
.a-body p { margin: 0 0 1em; text-align: justify; text-justify: inter-ideograph; }
.a-body p:last-child { margin-bottom: 0; }
.a-body .ink { animation: ink .7s ease-out both; }
@keyframes ink { from { opacity: 0; filter: blur(3px); } to { opacity: 1; filter: blur(0); } }
.a.done .a-body::after {
  content: ""; display: block; width: 22px; height: 1px; background: var(--seal); opacity: .6; margin-top: 18px;
}
.a-error { color: var(--seal); font-size: 14px; }

/* 思考中:水墨晕开 */
.thinking { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; padding: 6px 0; }
.ripple { position: relative; width: 26px; height: 26px; }
.ripple i { position: absolute; inset: 0; border-radius: 50%; border: 1px solid var(--ink); opacity: 0; animation: ripple 2.4s ease-out infinite; }
.ripple i:nth-child(2) { animation-delay: .8s; }
.ripple i:nth-child(3) { animation-delay: 1.6s; border-color: var(--seal); }
.ripple::after { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--ink); opacity: .85; }
@keyframes ripple { 0% { transform: scale(.3); opacity: .7; } 100% { transform: scale(1.5); opacity: 0; } }

/* 输入栏 */
.composer {
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 70%, transparent);
  position: relative; z-index: 2;
}
.ask {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 26px;
  padding: 6px 6px 6px 18px; box-shadow: var(--shadow);
  transition: border-color .25s;
}
.ask:focus-within { border-color: color-mix(in srgb, var(--ink) 40%, transparent); }
.ask textarea {
  flex: 1; border: 0; outline: none; resize: none; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.6; padding: 9px 0; max-height: 140px;
}
.ask textarea::placeholder { color: var(--muted); }
.send {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--ink); color: var(--paper); display: grid; place-items: center;
  transition: opacity .2s, transform .2s;
}
.send:active { transform: scale(.94); }
.send[disabled] { opacity: .25; }
.send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.quota { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

/* 关于 */
.about {
  border: 1px solid var(--line); border-radius: 18px; padding: 26px 24px 22px; max-width: 360px; width: calc(100% - 40px);
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow);
}
.about::backdrop { background: rgba(20, 16, 12, .45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.about h2 { font-family: var(--serif); font-size: 19px; margin: 0 0 14px; letter-spacing: .08em; }
.about p { font-size: 14px; line-height: 1.85; color: var(--ink-2); margin: 0 0 10px; }
.about .btn-ink { width: 100%; margin-top: 10px; height: 46px; font-size: 15px; }

:focus-visible { outline: 2px solid var(--seal); outline-offset: 3px; }
.gate-form input:focus-visible { outline: none; border-bottom: 2px solid var(--seal); }
.ask textarea:focus-visible { outline: none; }
.ask:has(textarea:focus-visible) { border-color: var(--seal); }
.starter:hover { border-color: color-mix(in srgb, var(--seal) 50%, var(--line)); }

@media (min-width: 760px) {
  :root { --gutter: 32px; }
  .gate { justify-content: center; }
  .name { font-size: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
