:root {
  --sky-top: #070919;
  --sky-mid: #141a3d;
  --sky-low: #3a2a55;
  --ink: #0b0d1a;
  --panel: rgba(16, 18, 36, 0.78);
  --line: rgba(232, 194, 122, 0.22);
  --gold: #e8c27a;
  --gold-hi: #ffe2a8;
  --red: #c8402f;
  --text: #efe6d2;
  --dim: #a39a86;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "楷体", var(--serif);
  --tab-h: calc(62px + env(safe-area-inset-bottom));
}
body[data-time="dawn"] { --sky-top: #131a3a; --sky-mid: #4a3a6a; --sky-low: #c9785a; }
body[data-time="day"]  { --sky-top: #0c1f3c; --sky-mid: #1f4a6e; --sky-low: #5d8a96; }
body[data-time="dusk"] { --sky-top: #14122e; --sky-mid: #55305a; --sky-low: #c2553c; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 58%, var(--sky-low) 100%) fixed;
  background-color: var(--ink);
  color: var(--text);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.7;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }

#sky { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }

main {
  position: relative; z-index: 1;
  height: 100%;
  max-width: 520px; margin: 0 auto;
}
.hall {
  position: absolute; inset: 0 0 var(--tab-h) 0;
  display: none; flex-direction: column;
  padding: calc(18px + env(safe-area-inset-top)) 18px 12px;
  animation: enter 0.5s ease both;
}
body[data-hall="gate"] .hall[data-hall="gate"],
body[data-hall="chat"] .hall[data-hall="chat"],
body[data-hall="fish"] .hall[data-hall="fish"],
body[data-hall="sign"] .hall[data-hall="sign"],
body[data-hall="sutra"] .hall[data-hall="sutra"] { display: flex; }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* 没在山门时给内容垫一层暗色，保证可读 */
body:not([data-hall="gate"]) main::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: rgba(7, 8, 20, 0.62);
  backdrop-filter: blur(2px);
}

.hall-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.hall-head h2 { margin: 0; font-size: 26px; letter-spacing: 0.2em; color: var(--gold); font-weight: 600; }
.hall-head p { margin: 0; flex: 1; font-size: 13px; color: var(--dim); }

.primary {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0 26px; border-radius: 999px;
  background: linear-gradient(180deg, #d9573f, #a52e20);
  color: #fff3e0; letter-spacing: 0.15em; text-decoration: none;
  box-shadow: 0 6px 20px rgba(200, 64, 47, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.12s;
}
.primary:active { transform: scale(0.96); }
.primary:disabled { opacity: 0.5; }
.ghost {
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--gold); font-size: 14px;
}
.ghost:active { background: rgba(232, 194, 122, 0.12); }
.row { display: flex; align-items: center; justify-content: center; gap: 14px; }

/* ───── 山门 ───── */
.hall[data-hall="gate"] { padding-left: 0; padding-right: 0; padding-bottom: 0; }
.gate-head { display: flex; gap: 18px; padding: 8px 24px 0; position: relative; z-index: 3; }
.temple-name {
  margin: 0; display: flex; flex-direction: column;
  font-size: clamp(44px, 13vw, 64px); line-height: 1.12; font-weight: 700;
  color: var(--gold-hi);
  text-shadow: 0 0 28px rgba(255, 200, 110, 0.45), 0 2px 0 rgba(0, 0, 0, 0.4);
}
.temple-name span { animation: enter 0.9s ease both; }
.temple-name span:nth-child(2) { animation-delay: 0.15s; }
.temple-name span:nth-child(3) { animation-delay: 0.3s; }
.gate-meta { padding-top: 12px; border-left: 1px solid var(--line); padding-left: 16px; }
.gate-meta p { margin: 0; }
.lunar { font-size: 15px; color: var(--gold); letter-spacing: 0.12em; }
.shichen { font-size: 13px; color: var(--dim); margin-top: 2px !important; }
.greet { margin-top: 14px !important; font-size: 15px; line-height: 1.9; max-width: 13em; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6); }

.crowd { margin: 10px 0 0 !important; min-height: 1.5em; font-size: 12px; line-height: 1.5; color: var(--dim); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6); }
.crowd.center { text-align: center; margin: 6px 0 4px !important; }
.scene { position: relative; flex: 1; min-height: 0; margin-top: -30px; }
.scene-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.moon { fill: #fff3cf; }
.mt.far { fill: #1b2147; opacity: 0.85; }
.mt.mid { fill: #121631; }
.mt.near { fill: #070814; }
.temple { fill: #05060f; }
.windows { fill: url(#winGlow); filter: drop-shadow(0 0 5px rgba(255, 170, 70, 0.9)); animation: flicker 5s ease-in-out infinite; }
.lamps { fill: #ff7a3d; filter: drop-shadow(0 0 4px #ff7a3d); animation: flicker 3.2s ease-in-out infinite; }
@keyframes flicker { 0%, 100% { opacity: 1; } 45% { opacity: 0.78; } 60% { opacity: 0.95; } 75% { opacity: 0.7; } }

.ripples, .lantern-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ripple {
  position: absolute; left: 50%; top: 62%; width: 60px; height: 60px; margin: -30px;
  border: 1.5px solid var(--gold-hi); border-radius: 50%;
  animation: ripple 3.6s ease-out forwards;
}
@keyframes ripple { from { transform: scale(0.4); opacity: 0.8; } to { transform: scale(11); opacity: 0; } }

.lantern {
  position: absolute; bottom: 22%; width: 34px; height: 44px; margin-left: -17px;
  border-radius: 9px 9px 13px 13px / 12px 12px 18px 18px;
  background: radial-gradient(circle at 50% 78%, #fff1b8 0%, #ffab4a 42%, #c9502a 100%);
  box-shadow: 0 0 22px 6px rgba(255, 160, 70, 0.55);
  animation: rise var(--dur, 16s) linear forwards;
}
.lantern::after {
  content: attr(data-text); position: absolute; left: 50%; top: 100%; transform: translateX(-50%);
  margin-top: 6px; white-space: nowrap; font-size: 12px; color: var(--gold-hi); opacity: 0.85;
  text-shadow: 0 1px 4px #000;
}
@keyframes rise {
  0% { transform: translate(0, 0) scale(1); opacity: 0; }
  6% { opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--drift, 30px), -78vh) scale(0.35); opacity: 0; }
}

.gate-actions {
  position: absolute; right: 18px; bottom: 58px; z-index: 4;
  display: flex; flex-direction: column; gap: 14px;
}
.orb {
  width: 68px; height: 68px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--line); color: var(--gold);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  position: relative; transition: transform 0.12s;
}
.orb:active { transform: scale(0.93); }
.orb svg { width: 24px; height: 24px; }
.orb b { font-size: 12px; font-weight: 400; letter-spacing: 0.1em; line-height: 1.3; }
.orb i {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--red); color: #fff; font: 11px/20px system-ui, sans-serif; text-align: center;
}
.orb i:empty { display: none; }
.orb.swing svg { animation: swing 1.4s ease-out; transform-origin: 50% 10%; }
@keyframes swing { 0% { transform: rotate(0); } 15% { transform: rotate(18deg); } 35% { transform: rotate(-14deg); } 55% { transform: rotate(9deg); } 75% { transform: rotate(-5deg); } 100% { transform: rotate(0); } }

.lantern-form {
  position: absolute; left: 18px; right: 100px; bottom: 58px; z-index: 5;
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  padding: 12px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: enter 0.3s ease both;
}
.lantern-form input, #signWorry {
  min-width: 0; height: 42px; padding: 0 14px; border-radius: 21px;
  border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35); outline: none;
  user-select: text; -webkit-user-select: text;
}
.lantern-form input:focus, #signWorry:focus, .chat-form textarea:focus { border-color: var(--gold); }
.lantern-form button { padding: 0 16px; border-radius: 21px; background: var(--gold); color: #2a1a05; }
.lantern-form p { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--dim); }

.fine {
  position: absolute; left: 0; right: 0; bottom: 10px; z-index: 3; margin: 0; padding: 0 16px;
  text-align: center; font-size: 11px; color: rgba(239, 230, 210, 0.62); line-height: 1.5;
  padding-top: 26px; padding-bottom: 10px; bottom: 0;
  background: linear-gradient(180deg, rgba(5, 6, 15, 0), rgba(5, 6, 15, 0.92) 55%);
}

/* ───── 禅房 ───── */
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 2px 12px; display: flex; flex-direction: column; gap: 14px; scrollbar-width: none; }
.chat-log::-webkit-scrollbar { display: none; }
.msg { max-width: 86%; padding: 11px 15px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text; animation: enter 0.3s ease both; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg.me { align-self: flex-end; background: linear-gradient(180deg, #7c2a1f, #5e1d15); border-top-right-radius: 4px; }
.msg.err { align-self: center; font-size: 13px; color: var(--dim); background: none; }
.msg.typing::after { content: "▍"; color: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; color: var(--gold); background: rgba(0, 0, 0, 0.25); }
.chat-form { display: flex; gap: 10px; align-items: flex-end; }
.chat-form textarea {
  flex: 1; min-height: 46px; max-height: 120px; padding: 10px 16px; border-radius: 23px; resize: none;
  border: 1px solid var(--line); background: rgba(0, 0, 0, 0.4); outline: none; line-height: 1.5;
  user-select: text; -webkit-user-select: text;
}
.chat-form button { width: 46px; height: 46px; flex: none; border-radius: 50%; background: var(--gold); color: #2a1a05; display: grid; place-items: center; }
.chat-form button svg { width: 22px; height: 22px; }
.chat-form button:disabled { opacity: 0.4; }

/* ───── 木鱼 ───── */
.fish-stats { display: flex; justify-content: center; gap: 44px; }
.fish-stats div { text-align: center; }
.fish-stats b { display: block; font-size: 38px; line-height: 1.1; color: var(--gold-hi); font-weight: 600; font-variant-numeric: tabular-nums; }
.fish-stats span { font-size: 12px; color: var(--dim); letter-spacing: 0.3em; }
.fish-stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; }
.fish { position: relative; width: min(72vw, 300px); touch-action: manipulation; transition: transform 0.09s ease-out; filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.5)); }
.fish svg { display: block; width: 100%; }
.fish.hit { transform: scale(0.94) translateY(4px); }
.mallet {
  position: absolute; right: -12%; top: -2%; width: 104px; height: 14px; border-radius: 7px;
  background: linear-gradient(90deg, #6b3a1c, #c98a4a); transform-origin: 100% 50%; transform: rotate(16deg);
  transition: transform 0.09s ease-out; pointer-events: none;
}
.mallet::before { content: ""; position: absolute; left: -18px; top: -11px; width: 36px; height: 36px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #e8b070, #7a3a1e); }
.mallet.hit { transform: rotate(-20deg); }
.float {
  position: absolute; left: 50%; top: 30%; pointer-events: none; white-space: nowrap;
  color: var(--gold-hi); font-size: 18px; letter-spacing: 0.1em; text-shadow: 0 2px 8px #000;
  animation: floatUp 1.1s ease-out forwards;
}
@keyframes floatUp { from { transform: translate(-50%, 0); opacity: 1; } to { transform: translate(-50%, -90px); opacity: 0; } }
.fish-quote { min-height: 3.4em; margin: 0 auto 10px; max-width: 20em; text-align: center; color: var(--text); font-size: 15px; transition: opacity 0.4s; }
.fish-tools { display: flex; justify-content: center; gap: 26px; padding-bottom: 6px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dim); }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 38px; height: 22px; border-radius: 11px; background: rgba(255, 255, 255, 0.14); position: relative; transition: background 0.2s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch input:checked + span { background: var(--red); }
.switch input:checked + span::after { transform: translateX(16px); }

/* ───── 禅签 ───── */
.sign-idle { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.tube { position: relative; width: 110px; height: 190px; transform-origin: 50% 100%; }
.tube-body {
  position: absolute; left: 0; right: 0; bottom: 0; height: 130px; border-radius: 10px 10px 18px 18px;
  background: linear-gradient(90deg, #5b1d14, #b23a28 45%, #6b2218); border: 1px solid rgba(255, 200, 140, 0.3);
  display: grid; place-items: center; box-shadow: 0 16px 30px rgba(0, 0, 0, 0.5);
}
.tube-body span { width: 46px; height: 46px; border-radius: 50%; border: 1.5px solid var(--gold); color: var(--gold); display: grid; place-items: center; font-size: 22px; }
.tube i { position: absolute; bottom: 110px; width: 9px; height: 74px; border-radius: 3px; background: linear-gradient(180deg, #f1d79b, #b88945); transform-origin: 50% 100%; }
.tube i:nth-child(1) { left: 22px; transform: rotate(-12deg); }
.tube i:nth-child(2) { left: 38px; transform: rotate(-5deg); height: 82px; }
.tube i:nth-child(3) { left: 51px; height: 88px; }
.tube i:nth-child(4) { left: 64px; transform: rotate(6deg); height: 80px; }
.tube i:nth-child(5) { left: 79px; transform: rotate(13deg); }
.tube.shake { animation: shake 0.9s ease-in-out; }
.tube.shake i:nth-child(3) { animation: pop 0.9s ease-in forwards; }
@keyframes shake { 0%, 100% { transform: rotate(0); } 12% { transform: rotate(-16deg); } 26% { transform: rotate(14deg); } 40% { transform: rotate(-12deg); } 54% { transform: rotate(10deg); } 68% { transform: rotate(-7deg); } 84% { transform: rotate(4deg); } }
@keyframes pop { 0%, 55% { transform: translateY(0); } 100% { transform: translateY(-46px); } }
#signWorry { width: min(100%, 320px); text-align: center; }
.hint { margin: 0; font-size: 12px; color: var(--dim); min-height: 1.6em; }

.sign-result { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; scrollbar-width: none; }
.sign-card {
  margin: auto 0; padding: 26px 24px 22px; border-radius: 18px; position: relative;
  background: linear-gradient(170deg, #f6ecd4, #e7d5ac); color: #2b1c10;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55); animation: enter 0.6s ease both;
  user-select: text; -webkit-user-select: text;
}
.sign-card::before { content: ""; position: absolute; inset: 8px; border: 1px solid rgba(140, 60, 30, 0.35); border-radius: 12px; pointer-events: none; }
.sign-date { margin: 0; font-size: 12px; color: #8a6a44; letter-spacing: 0.15em; text-align: center; }
.sign-text { margin: 16px 0 8px; font-size: clamp(24px, 7vw, 32px); line-height: 1.5; text-align: center; font-family: var(--kai); font-weight: 600; color: #7c1f14; }
.sign-src { margin: 0 0 16px; text-align: center; font-size: 13px; color: #8a6a44; }
.sign-read { margin: 0 0 16px; font-size: 15px; line-height: 1.85; min-height: 4em; }
.sign-read.typing::after { content: "▍"; color: #a52e20; animation: blink 1s steps(2) infinite; }
.sign-yj { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 1px dashed rgba(140, 60, 30, 0.35); padding-top: 14px; }
.sign-yj p { margin: 0; display: flex; gap: 8px; align-items: center; font-size: 14px; }
.sign-yj b { width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 13px; color: #f6ecd4; background: #a52e20; }
.sign-yj p:last-child b { background: #3c4a5c; }

/* ───── 抄经 ───── */
.sutra-line { margin: 0 0 12px; text-align: center; font-family: var(--kai); font-size: 20px; letter-spacing: 0.25em; min-height: 1.7em; color: var(--dim); }
.sutra-line b { color: var(--gold-hi); font-weight: 400; }
.sutra-line s { text-decoration: none; color: var(--text); }
.paper {
  position: relative; flex: 1; min-height: 0; width: 100%; max-height: min(100vw - 36px, 484px); aspect-ratio: 1; margin: 0 auto;
  border-radius: 14px; background: #f1e6c9; overflow: hidden; touch-action: none;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), inset 0 0 60px rgba(160, 110, 50, 0.25);
  background-image:
    linear-gradient(rgba(170, 60, 40, 0.28), rgba(170, 60, 40, 0.28)),
    linear-gradient(rgba(170, 60, 40, 0.28), rgba(170, 60, 40, 0.28));
  background-size: 1px 100%, 100% 1px; background-position: 50% 0, 0 50%; background-repeat: no-repeat;
}
.paper::before { content: ""; position: absolute; inset: 10px; border: 2px solid rgba(170, 60, 40, 0.5); border-radius: 6px; pointer-events: none; }
.ghost-char { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--kai); color: rgba(120, 50, 30, 0.2); line-height: 1; pointer-events: none; }
#ink { position: absolute; inset: 0; width: 100%; height: 100%; }
.paper.done { animation: stamp 0.35s ease; }
@keyframes stamp { 50% { transform: scale(0.985); } }
.sutra-bar { height: 3px; margin: 14px 0 12px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.sutra-bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.4s; }
.sutra-count { flex: 1; text-align: center; font-size: 13px; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ───── 底栏 ───── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; height: var(--tab-h);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center;
  background: rgba(7, 8, 20, 0.82); border-top: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.tabs button { flex: 1; max-width: 104px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; color: var(--dim); letter-spacing: 0.1em; transition: color 0.2s; }
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--gold-hi); }
.tabs button.on svg { filter: drop-shadow(0 0 6px rgba(255, 200, 110, 0.7)); }

/* ───── 弹层 ───── */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(0, 0, 0, 0.78); backdrop-filter: blur(6px); }
.modal-box { max-width: 380px; width: 100%; text-align: center; }
.modal-box img { width: 100%; max-height: 68vh; object-fit: contain; border-radius: 12px; box-shadow: 0 20px 50px #000; -webkit-touch-callout: default; user-select: auto; -webkit-user-select: auto; }
.modal-box p { font-size: 13px; color: var(--dim); margin: 12px 0; }

@media (min-height: 800px) { .gate-actions, .lantern-form { bottom: 70px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
