/* Element Reading — base + shared components (spine). Agents extend in page css, never edit this. */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--ink-950);
  color: var(--cream);
  font-size: 17px;
  line-height: 1.65;
  min-height: 100dvh;
  overflow-x: hidden;
}
/* temple backdrop on every page */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -2;
  background: url("/assets/img/ui/bg-temple.webp") center top / cover no-repeat var(--ink-950);
}
body::after {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse 120% 60% at 50% 0%, rgba(20,11,8,.25), rgba(20,11,8,.86) 70%),
    linear-gradient(180deg, rgba(20,11,8,.35), rgba(20,11,8,.93));
}
img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--gold-400); }

/* desktop = jewel-box phone stage; mobile = full bleed */
.stage {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
@media (min-width: 720px) {
  .stage {
    border-left: 1px solid rgba(245,197,66,.18);
    border-right: 1px solid rgba(245,197,66,.18);
    background: rgba(20,11,8,.30);
    box-shadow: 0 0 80px rgba(0,0,0,.5);
  }
}

/* type */
h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: .015em;
  color: var(--gold-300);
}
.gold-text {
  background: var(--grad-gold-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.6));
}
.hanzi {
  font-family: var(--font-hanzi);
  color: var(--lacquer-500);
  opacity: .9;
}
.muted-line { color: rgba(255,246,229,.62); font-size: .92em; }
p + p { margin-top: .85em; }
em { color: var(--gold-300); font-style: italic; }
strong { color: var(--gold-400); font-weight: 800; }

/* panels */
.panel {
  background: var(--grad-panel);
  border: var(--rim-gold);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  padding: 22px 18px;
}
.panel--lacquer { background: var(--grad-lacquer); border-color: rgba(255,233,168,.5); }

/* gold button */
.btn-gold {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 52px;
  padding: 13px 26px;
  border: 1px solid rgba(255,243,196,.7);
  border-radius: 999px;
  background: var(--grad-gold);
  color: #3A2405;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .03em;
  text-decoration: none;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.5), inset 0 2px 2px rgba(255,255,255,.55), inset 0 -3px 6px rgba(140,90,10,.55);
  transition: transform .12s ease, box-shadow .25s ease, filter .2s ease;
}
.btn-gold:active { transform: translateY(2px); box-shadow: 0 2px 8px rgba(0,0,0,.5), inset 0 2px 2px rgba(255,255,255,.4); }
.btn-gold:disabled { filter: grayscale(.7) brightness(.7); pointer-events: none; }
.btn-gold.pulse { animation: btnPulse 1.9s ease-in-out infinite; }
@keyframes btnPulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(0,0,0,.5), 0 0 0 0 rgba(245,197,66,.55), inset 0 2px 2px rgba(255,255,255,.55); }
  50%      { box-shadow: 0 6px 22px rgba(0,0,0,.55), 0 0 26px 7px rgba(245,197,66,.33), inset 0 2px 2px rgba(255,255,255,.55); }
}
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 11px 22px;
  background: rgba(255,246,229,.06);
  border: 1px solid rgba(255,246,229,.35);
  border-radius: 999px;
  color: var(--cream);
  font-weight: 700; font-size: 15.5px;
}

/* Shen speech bubble */
.shen-row { display: flex; align-items: flex-end; gap: 10px; }
.shen-pic { width: 96px; flex: 0 0 auto; filter: drop-shadow(0 6px 14px rgba(0,0,0,.6)); }
.shen-bubble {
  position: relative;
  background: linear-gradient(180deg, rgba(253,243,220,.97), rgba(244,226,193,.97));
  color: #3A2810;
  border: 1px solid rgba(156,107,23,.55);
  border-radius: 18px;
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.55;
  box-shadow: 0 8px 22px rgba(0,0,0,.45);
}
.shen-bubble::after {
  content: "";
  position: absolute; left: -9px; bottom: 18px;
  border: 9px solid transparent;
  border-right-color: rgba(244,226,193,.97);
  border-left-width: 0;
}
.shen-bubble strong { color: #7A1313; }
.shen-bubble em { color: #7A1313; }
.shen-bubble.typing::after { }
.shen-name {
  font-family: var(--font-display);
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
  color: #9C6B17; margin-bottom: 4px;
}

/* chips + seals */
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(20,11,8,.72);
  border: 1px solid rgba(245,197,66,.5);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 800; font-size: 15px;
  color: var(--gold-300);
  box-shadow: var(--glow-gold);
}
.seal-img { width: 110px; height: 110px; filter: drop-shadow(0 8px 18px rgba(0,0,0,.6)); }

/* mute toggle (mounted by ERA.mountMute) */
.mute-btn {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 12px; z-index: 60;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(245,197,66,.55);
  background: rgba(20,11,8,.7);
  color: var(--gold-400);
  font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.mute-btn .mute-off { display: none; }
.mute-btn.is-muted .mute-on { display: none; }
.mute-btn.is-muted .mute-off { display: block; }

/* silk wipe page transition */
.silk-wipe {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(100deg, transparent 0%, var(--lacquer-700) 18%, var(--lacquer-600) 50%, #5E0C0C 82%, transparent 100%);
  background-size: 260% 100%;
  background-position: 130% 0;
  pointer-events: none;
  opacity: 0;
}
.silk-wipe.on {
  pointer-events: all;
  animation: silk .5s ease-in forwards;
}
@keyframes silk {
  0%   { opacity: 0; background-position: 130% 0; }
  35%  { opacity: 1; }
  100% { opacity: 1; background-position: 40% 0; }
}
.page-enter { animation: pageIn .55s ease-out both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* fx primitives (used by fx.js) — all live inside #fx-layer, a stage-width clipped
   overlay. Root overflow-x:clip does not clip position:fixed elements in Safari,
   and on desktop the visual canvas is the 520px jewel-box column. */
#fx-layer {
  position: fixed;
  top: 0; bottom: 0;
  left: max(0px, calc((100vw - 520px) / 2));
  width: min(100vw, 520px);
  overflow: clip;
  pointer-events: none;
  z-index: 90;
}
.fx-spark {
  position: absolute; z-index: 2; pointer-events: none;
  color: var(--gold-300);
  text-shadow: 0 0 8px rgba(245,197,66,.9);
  animation: spark .75s ease-out forwards;
}
@keyframes spark {
  from { transform: translate(-50%,-50%) scale(.5); opacity: 1; }
  to   { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.25) rotate(40deg); opacity: 0; }
}
.fx-ghost {
  position: absolute; z-index: 1; pointer-events: none;
  transition: transform .5s cubic-bezier(.5,-.1,.3,1), opacity .5s ease;
}
.fx-goldflash {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: radial-gradient(circle at 50% 38%, rgba(255,233,168,.85), rgba(245,197,66,.25) 40%, transparent 72%);
  animation: goldflash 1.1s ease-out forwards;
}
@keyframes goldflash { from { opacity: 0; transform: scale(.6); } 18% { opacity: 1; } to { opacity: 0; transform: scale(1.6); } }
.fx-drift {
  position: absolute; top: -4%; z-index: 1; pointer-events: none;
  color: rgba(245,197,66,.5);
  animation: driftDown linear infinite;
}
@keyframes driftDown {
  from { transform: translateY(-4vh) translateX(0) rotate(0); opacity: 0; }
  12%  { opacity: .8; }
  to   { transform: translateY(108vh) translateX(7vw) rotate(220deg); opacity: 0; }
}

/* ============ v2: chat bubbles ============ */
.chat-log { display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }

/* v3 messenger model: the scroller is bottom-anchored — when the conversation is
   short it hugs the foot, and new messages push history upward like any messenger.
   ERChat marks the scrollable ancestor with .chat-scroller (or the log itself). */
.chat-scroller {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.chat-scroller > .chat-log { margin-top: auto; }
.chat-log--self-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.chat-log--self-scroll > :first-child { margin-top: auto; }

/* "new message" pill — sticky at the conversation's bottom edge while scrolled up */
.chat-newpill {
  position: sticky;
  bottom: 8px;
  align-self: center;
  display: none;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(245,197,66,.65);
  background: rgba(20,11,8,.92);
  color: var(--gold-300);
  font-weight: 800;
  font-size: 13.5px;
  box-shadow: 0 6px 18px rgba(0,0,0,.5), var(--glow-gold);
  z-index: 5;
}
.chat-newpill.is-on { display: inline-flex; animation: chatIn .3s ease-out both; }
.chat-b {
  max-width: 88%;
  padding: 12px 15px;
  border-radius: 17px;
  font-size: 16px;
  line-height: 1.55;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  animation: chatIn .35s ease-out both;
}
@keyframes chatIn { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
.chat-b--shen {
  align-self: flex-start;
  background: linear-gradient(180deg, rgba(253,243,220,.97), rgba(244,226,193,.97));
  color: #3A2810;
  border: 1px solid rgba(156,107,23,.55);
  border-bottom-left-radius: 6px;
}
.chat-b--shen strong { color: #7A1313; }
.chat-b--shen em { color: #7A1313; }
.chat-b__name {
  font-family: var(--font-display);
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: #9C6B17; margin-bottom: 4px;
}
.chat-b--user {
  align-self: flex-end;
  background: var(--grad-lacquer);
  color: var(--porcelain);
  border: 1px solid rgba(255,233,168,.45);
  border-bottom-right-radius: 6px;
  font-weight: 700;
}
.chat-typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.chat-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #9C6B17; opacity: .4;
  animation: chatDot 1s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .16s; }
.chat-typing span:nth-child(3) { animation-delay: .32s; }
@keyframes chatDot { 0%, 100% { opacity: .25; transform: translateY(0); } 50% { opacity: .9; transform: translateY(-3px); } }
.chat-chips {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  padding: 6px 0 2px;
  animation: chatIn .35s ease-out both;
}
.chat-chip {
  min-height: 48px;
  padding: 11px 22px;
  border-radius: 999px;
  border: 1px solid rgba(255,243,196,.7);
  background: var(--grad-gold);
  color: #3A2405;
  font-family: var(--font-display);
  font-weight: 700; font-size: 15.5px;
  box-shadow: 0 5px 14px rgba(0,0,0,.45), inset 0 2px 2px rgba(255,255,255,.5);
}
.chat-chip:active { transform: translateY(2px); }
.chat-chip--ghost {
  background: rgba(255,246,229,.07);
  border-color: rgba(255,246,229,.4);
  color: var(--cream);
}
.chat-slot { display: flex; justify-content: center; padding: 6px 0; animation: chatIn .4s ease-out both; }

/* ============ v2: arrival curtain ============ */
.curtain {
  position: fixed; inset: 0; z-index: 98;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse 130% 70% at 50% 0%, rgba(42,24,16,.65), rgba(20,11,8,.97) 70%),
    var(--ink-950);
  transition: opacity .6s ease, transform .6s ease;
  overflow: hidden;
}
.curtain.is-lifting { opacity: 0; transform: scale(1.04); pointer-events: none; }
body.curtain-open { overflow: hidden; }
.curtain__inner {
  width: min(420px, 86vw);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.curtain__logo { width: 92px; filter: drop-shadow(0 0 22px rgba(245,197,66,.4)); animation: curtainSpin 14s linear infinite; }
@keyframes curtainSpin { to { transform: rotate(360deg); } }
.curtain__line {
  min-height: 3.2em;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 17px; color: var(--gold-300);
  opacity: 0;
}
.curtain__line.is-in { animation: curtainLine 1.55s ease both; }
@keyframes curtainLine { 0% { opacity: 0; transform: translateY(8px); } 18% { opacity: 1; transform: none; } 86% { opacity: 1; } 100% { opacity: .35; } }
.curtain__bar {
  width: 78%; height: 5px; border-radius: 999px;
  background: rgba(255,246,229,.12);
  border: 1px solid rgba(245,197,66,.25);
  overflow: hidden;
}
.curtain__bar i {
  display: block; height: 100%; width: 4%;
  background: var(--grad-gold);
  box-shadow: 0 0 12px rgba(245,197,66,.8);
  transition: width 1.2s cubic-bezier(.3,.6,.4,1);
}
.curtain__btn { min-width: 240px; }

/* footer */
.site-foot {
  margin-top: auto;
  padding-top: 26px;
  text-align: center;
  font-size: 12px;
  color: rgba(255,246,229,.5);
}
.site-foot a { color: rgba(255,233,168,.65); text-decoration: none; margin: 0 6px; }

/* focus + reduced motion */
:focus-visible { outline: 2px solid var(--gold-400); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
