/* ============================================================
   字里行间 — 样式（宣纸与墨，全部程序化，无外部资源）
   ============================================================ */

:root {
  --paper: #efe7d4;
  --paper-deep: #e6dcc4;
  --ink: #211d18;
  --ink-soft: #4a423a;
  --ink-faint: #8a7f6e;
  --gold: #b08c3c;
  --seal: #b3402f;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "SimSun", serif;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "楷体", "Songti SC", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
.about-body, .intro-text { -webkit-user-select: text; user-select: text; }

.screen { position: fixed; inset: 0; display: none; animation: screenIn .7s ease both; }
.screen.active { display: block; }
@keyframes screenIn { from { opacity: 0; } to { opacity: 1; } }

/* 宣纸底（程序化纹理由 CSS 渐变叠加） */
.paper-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255,255,255,.5), transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(140,115,75,.12), transparent 60%),
    linear-gradient(180deg, #f1e9d6, #e9dfc8);
}
.paper-bg::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(105deg, transparent 0 26px, rgba(120,100,70,.025) 26px 27px),
              repeating-linear-gradient(15deg, transparent 0 34px, rgba(120,100,70,.02) 34px 35px);
  pointer-events: none;
}

/* ==================== 标题 ==================== */
#screen-title { overflow: hidden; }
.title-inner {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding-bottom: 6vh;
}
.title-sub { letter-spacing: .55em; text-indent: .55em; color: var(--ink-faint); font-size: 15px; margin-bottom: 22px; }
.title-main {
  font-size: clamp(64px, 13vw, 132px);
  font-weight: 400;
  letter-spacing: .12em;
  color: var(--ink);
  font-family: var(--kai);
  text-shadow: 2px 3px 0 rgba(33,29,24,.08);
  line-height: 1;
  animation: inkIn 1.6s ease both;
}
@keyframes inkIn {
  0% { opacity: 0; filter: blur(6px); transform: scale(1.06); }
  60% { opacity: 1; filter: blur(0); }
  100% { transform: scale(1); }
}
.title-en { margin-top: 14px; letter-spacing: .5em; text-indent: .5em; color: var(--gold); font-size: 12px; font-family: Georgia, serif; }
.title-menu { margin-top: 6.5vh; display: flex; flex-direction: column; gap: 13px; align-items: center; }
.menu-btn {
  background: none; border: 1px solid rgba(33,29,24,.4);
  color: var(--ink); padding: 12px 54px; font-size: 17px;
  letter-spacing: .5em; text-indent: .5em; transition: all .25s;
  min-width: 240px;
}
.menu-btn:hover { background: rgba(33,29,24,.07); letter-spacing: .68em; }
.seal {
  position: absolute; top: max(26px, env(safe-area-inset-top)); right: 28px;
  width: 46px; height: 46px; border: 2px solid rgba(179,64,47,.75);
  color: rgba(179,64,47,.85); font-family: var(--kai);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1.1; letter-spacing: 2px;
  transform: rotate(4deg); writing-mode: vertical-rl;
  opacity: .85; pointer-events: none;
}
.title-hint { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom)); width: 100%; color: var(--ink-faint); font-size: 12px; letter-spacing: .18em; padding: 0 20px; }
.title-ink {
  position: absolute; left: 50%; top: 12%; width: 14px; height: 14px;
  background: radial-gradient(circle at 35% 30%, #4a423a 0%, #211d18 55%);
  border-radius: 50%; z-index: 2;
  animation: inkFall 3.2s cubic-bezier(.5,0,.8,.4) infinite;
  opacity: .9;
}
@keyframes inkFall {
  0% { transform: translateY(-40px) scale(.6); opacity: 0; }
  18% { opacity: .9; }
  70% { transform: translateY(56vh) scale(1); opacity: .9; }
  85% { transform: translateY(60vh) scale(1.25, .85); opacity: .5; }
  100% { transform: translateY(61vh) scale(1.5, .5); opacity: 0; }
}

/* ==================== 通用 ==================== */
.overlay {
  background: rgba(64, 54, 38, .35);
  backdrop-filter: blur(3px);
  z-index: 40;
  display: none; align-items: center; justify-content: center;
}
.overlay.active { display: flex; }

.about-card {
  max-width: 600px; width: 92%; max-height: 84vh; overflow: auto;
  background: linear-gradient(180deg, #f4eddb, #ece2cb);
  border-radius: 4px; padding: 32px 36px; position: relative;
  box-shadow: 0 12px 50px rgba(40,30,15,.35);
}
.about-card h2 { font-family: var(--kai); font-weight: 400; letter-spacing: .3em; margin-bottom: 14px; border-bottom: 1px solid rgba(33,29,24,.2); padding-bottom: 10px; }
.about-body p { margin: 10px 0; line-height: 2; font-size: 15px; color: var(--ink-soft); }
.about-sign { text-align: right; color: var(--gold); font-family: var(--kai); }
.close-x {
  position: absolute; top: 8px; right: 12px; background: none; border: none;
  color: var(--ink-faint); font-size: 26px; line-height: 1;
}
.close-x:hover { color: var(--ink); }

.ghost-btn {
  background: none; border: 1px solid rgba(33,29,24,.35);
  color: var(--ink-soft); padding: 8px 20px; font-size: 14px;
  letter-spacing: .15em; transition: all .2s; white-space: nowrap;
}
.ghost-btn:hover { border-color: var(--gold); color: var(--ink); }
.ghost-btn.primary { border-color: rgba(176,140,60,.6); color: var(--ink); }
.ghost-btn.small { padding: 5px 12px; font-size: 12px; }

/* ==================== 序幕 / 终幕 ==================== */
.intro-stage {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0 10vw;
}
.intro-text {
  max-width: 680px; font-size: 19px; line-height: 2.4;
  color: var(--ink); font-family: var(--kai);
  min-height: 6.5em; white-space: pre-wrap; letter-spacing: .05em;
}
.intro-actions { margin-top: 5.5vh; display: flex; gap: 16px; }
.end-progress { margin-top: 3vh; color: var(--gold); letter-spacing: .2em; font-size: 14px; min-height: 20px; }

/* ==================== 游戏画布 ==================== */
#screen-game { background: #e9dfc8; }
#screen-game canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#ink-canvas { cursor: crosshair; }

#hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(10px + env(safe-area-inset-top)) 16px 0;
  display: flex; align-items: center; gap: 14px;
  pointer-events: none; z-index: 5;
}
#hud .ghost-btn { pointer-events: auto; }
#ink-meter {
  position: relative; width: 160px; height: 14px;
  background: rgba(33,29,24,.12); border-radius: 7px;
  overflow: hidden; border: 1px solid rgba(33,29,24,.25);
}
#inkfill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #2a2622, #4a423a);
  transition: width .2s ease, background .3s;
  border-radius: 6px;
}
.ink-label {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  color: rgba(239,231,212,.9); font-size: 10px; letter-spacing: 2px;
  font-family: var(--kai); text-shadow: 0 0 3px rgba(0,0,0,.4);
}
#lv-label {
  flex: 1; text-align: center; font-family: var(--kai);
  font-size: 15px; color: var(--ink-soft); letter-spacing: .2em;
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
}

/* 记忆碎片提示 */
.frag-toast {
  position: absolute; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(560px, 88vw);
  font-family: var(--kai); font-size: 16px; line-height: 1.9;
  color: var(--ink); text-align: center;
  background: rgba(244,237,219,.92);
  border: 1px solid rgba(33,29,24,.25);
  border-radius: 4px; padding: 12px 22px;
  box-shadow: 0 6px 30px rgba(40,30,15,.18);
  opacity: 0; pointer-events: none; z-index: 6;
  white-space: pre-wrap;
  transition: opacity .5s ease;
}
.frag-toast.flash { opacity: 1; }
.frag-toast.mini { font-size: 13px; padding: 6px 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }

/* ==================== 一字完成 ==================== */
.interlude-card {
  max-width: 480px; width: 90%;
  background: linear-gradient(180deg, #f4eddb, #ece2cb);
  border-radius: 4px; padding: 40px 36px 34px;
  text-align: center;
  box-shadow: 0 12px 50px rgba(40,30,15,.4);
  animation: cardIn .5s ease both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.it-char-wrap { margin-bottom: 18px; }
.it-char {
  font-family: var(--kai); font-size: 84px; color: var(--ink);
  display: inline-block;
  text-shadow: 3px 4px 0 rgba(33,29,24,.07);
}
.it-pinyin {
  font-family: Georgia, serif; color: var(--gold);
  font-size: 16px; margin-left: 10px; letter-spacing: .15em;
}
.it-mems { text-align: left; margin-bottom: 18px; }
.it-mem { margin: 12px 0; font-family: var(--kai); font-size: 15.5px; line-height: 2; color: var(--ink-soft); white-space: pre-wrap; }
.it-mem b {
  display: block; font-weight: 400; color: var(--gold);
  font-size: 12.5px; letter-spacing: .2em; margin-bottom: 2px;
}
.it-done {
  font-family: var(--kai); font-size: 17px; line-height: 2.2;
  color: var(--ink-soft); white-space: pre-wrap;
  margin-bottom: 26px; min-height: 4em;
}

/* ==================== 终幕 ==================== */
#screen-ending .intro-actions { justify-content: center; }

/* ==================== 响应式 ==================== */
@media (max-width: 600px) {
  .title-main { font-size: clamp(52px, 16vw, 84px); }
  .menu-btn { min-width: 210px; padding: 12px 40px; font-size: 15px; }
  .intro-text { font-size: 16px; line-height: 2.2; }
  .intro-stage { padding: 0 7vw; }
  .it-char { font-size: 64px; }
  .it-mems { text-align: left; margin-bottom: 18px; }
.it-mem { margin: 12px 0; font-family: var(--kai); font-size: 15.5px; line-height: 2; color: var(--ink-soft); white-space: pre-wrap; }
.it-mem b {
  display: block; font-weight: 400; color: var(--gold);
  font-size: 12.5px; letter-spacing: .2em; margin-bottom: 2px;
}
.it-done { font-size: 15px; }
  #ink-meter { width: 110px; }
  #lv-label { font-size: 12px; letter-spacing: .1em; }
  .frag-toast { font-size: 14px; bottom: calc(18px + env(safe-area-inset-bottom)); }
  .about-card { padding: 26px 22px; }
}
