:root {
  --ink: #25211d;
  --muted: #766e64;
  --paper: #f6f1e7;
  --surface: #fffdf8;
  --line: rgba(47, 39, 31, 0.14);
  --stone: #292d29;
  --gold: #c7ae75;
  --cinnabar: #92372d;
  --serif: "Songti SC", "Noto Serif CJK SC", "STSong", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body { overflow: hidden; color: var(--ink); background: #111310; font-family: var(--sans); }
button, textarea { font: inherit; }
button, label, a { -webkit-tap-highlight-color: transparent; }

.memorial-arrival {
  position: fixed;
  inset: 0;
  display: grid;
  overflow: hidden;
  place-items: center;
  outline: 0;
  cursor: pointer;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(225, 213, 178, 0.12), transparent 34%),
    linear-gradient(156deg, #111411, #363b35 52%, #0d0f0d);
}

.ambient-light {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(108deg, rgba(255, 247, 216, 0.07), transparent 30% 72%, rgba(0, 0, 0, 0.18));
}

.stone-scene {
  position: relative;
  display: grid;
  width: min(100%, 700px);
  height: 100dvh;
  min-height: 620px;
  place-items: center;
  padding: 24px;
}

.tablet {
  position: relative;
  width: min(340px, 76vw);
  aspect-ratio: .58;
  padding: 38px 28px 28px;
  color: #dfd0aa;
  text-align: center;
  border-radius: 48% 48% 10px 10px / 18% 18% 10px 10px;
  background:
    radial-gradient(ellipse at 31% 13%, rgba(255, 255, 235, 0.16), transparent 27%),
    radial-gradient(ellipse at 72% 74%, rgba(0, 0, 0, 0.3), transparent 42%),
    linear-gradient(90deg, rgba(255,255,255,0.14), transparent 18%, rgba(0,0,0,0.3) 82%),
    linear-gradient(160deg, #62675f, #2a2e29 55%, #11130f);
  box-shadow:
    inset 12px 10px 18px rgba(255,255,235,0.08),
    inset -24px -18px 34px rgba(0,0,0,0.5),
    inset 0 0 0 1px rgba(244, 229, 185, 0.1),
    13px 19px 0 rgba(5, 6, 5, 0.36),
    28px 44px 80px rgba(0,0,0,0.6);
  animation: arrive 650ms cubic-bezier(.2,.8,.2,1) both;
}

.tablet::before {
  position: absolute;
  inset: 16px;
  content: "";
  pointer-events: none;
  border: 1px solid rgba(224, 207, 160, 0.28);
  border-radius: inherit;
  box-shadow: inset 2px 2px 3px rgba(255, 246, 214, 0.11), inset -4px -5px 9px rgba(0, 0, 0, 0.44);
}

.tablet::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  border-radius: inherit;
  background: repeating-linear-gradient(98deg, rgba(255,255,255,0.018) 0 2px, rgba(0,0,0,0.024) 2px 5px);
  mix-blend-mode: screen;
}

.portrait {
  position: relative;
  z-index: 2;
  width: 80px;
  height: 96px;
  margin: 8px auto 16px;
  overflow: hidden;
  border: 1px solid rgba(218, 199, 153, 0.25);
  border-radius: 48% 48% 9px 9px / 26% 26% 9px 9px;
  background: linear-gradient(145deg, rgba(8, 10, 8, 0.48), rgba(255, 255, 230, 0.04));
  box-shadow: inset 2px 2px 4px rgba(255, 243, 203, 0.09), inset -5px -6px 12px rgba(0, 0, 0, 0.58), 0 5px 12px rgba(0, 0, 0, 0.24);
}

.portrait img { position: absolute; inset: 7px; width: calc(100% - 14px); height: calc(100% - 14px); object-fit: cover; opacity: 0; border-radius: inherit; filter: sepia(.14) contrast(.98); transition: opacity 1.2s ease; }
.portrait img.active { opacity: 1; }

.tablet-name {
  position: relative;
  z-index: 2;
  width: fit-content;
  margin: 0 auto;
  writing-mode: vertical-rl;
  color: #d7c193;
  font: 54px/1 var(--serif);
  letter-spacing: .18em;
  text-shadow: 1px 1px 0 rgba(255, 245, 205, .32), -1px -1px 0 rgba(10, 10, 8, .84), 0 3px 5px rgba(0, 0, 0, .58);
}

.tablet-years, .tablet-places, .tablet small {
  position: relative;
  z-index: 2;
  display: block;
  color: #cdb98e;
  font-family: var(--serif);
  text-shadow: 1px 1px 0 rgba(255, 244, 205, .18), -1px -1px 0 rgba(0, 0, 0, .74);
}
.tablet-years { margin-top: 13px; font-size: 13px; }
.tablet-places { margin-top: 7px; font-size: 11px; line-height: 1.35; }
.tablet small { margin-top: 14px; color: rgba(213, 196, 163, .68); font-size: 10px; }

.incense { position: absolute; bottom: calc(50% - min(293px, 43vw)); left: 50%; z-index: 4; display: flex; gap: 5px; align-items: end; height: 115px; transform: translateX(-50%); pointer-events: none; }
.incense > i { position: relative; display: block; width: 4px; height: 105px; border-radius: 2px; background: linear-gradient(#9d3427 0 66%, #21170f 66%); box-shadow: 0 8px 15px rgba(0,0,0,.42); }
.incense > i:nth-child(1) { height: 94px; transform: rotate(-2deg); }
.incense > i:nth-child(3) { height: 98px; transform: rotate(2deg); }
.incense > i::before { position: absolute; top: -4px; left: 0; width: 4px; height: 6px; content: ""; border-radius: 50%; background: #e5ad6c; box-shadow: 0 0 8px rgba(232, 154, 85, .8); }
.incense > i::after { position: absolute; bottom: 100%; left: -8px; width: 22px; height: 150px; content: ""; border-radius: 50%; background: linear-gradient(170deg, transparent 3%, rgba(220, 226, 213, .35) 28%, transparent 58%); filter: blur(6px); transform-origin: bottom; animation: smoke 6.8s ease-in-out infinite; }
.incense > i:nth-child(2)::after { animation-delay: -2.4s; }
.incense > i:nth-child(3)::after { animation-delay: -4.1s; }

.memorial-chat {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto minmax(150px, 30dvh) minmax(0, 1fr) auto;
  min-height: 100dvh;
  background: transparent;
  transform: translateY(102%);
  visibility: hidden;
  transition: transform 460ms cubic-bezier(.2,.8,.2,1), visibility 0s 460ms;
}
body.chat-open .memorial-chat { visibility: visible; transform: none; transition-delay: 0s; }
body.chat-open .memorial-arrival { place-items: start center; cursor: default; }
body.chat-open .stone-scene { height: 40dvh; min-height: 0; transform: none; transition: height 460ms cubic-bezier(.2,.8,.2,1); }
body.chat-open .tablet { position: absolute; bottom: -12px; left: clamp(16px, 9vw, 100px); width: clamp(132px, 23vw, 205px); padding: 18px 14px 16px; border-radius: 46% 46% 6px 6px / 17% 17% 6px 6px; animation: none; }
body.chat-open .portrait { width: 38px; height: 46px; margin: 2px auto 6px; }
body.chat-open .tablet-name { font-size: clamp(24px, 4vw, 36px); }
body.chat-open .tablet-years { margin-top: 5px; font-size: 7px; }
body.chat-open .tablet-places { margin-top: 3px; font-size: 6px; }
body.chat-open .tablet small { margin-top: 5px; font-size: 6px; }
body.chat-open .incense { bottom: 2px; left: 61%; height: 78px; transform: translateX(-50%) scale(.72); transform-origin: bottom; }
body.ritual-lit .incense > i::before { background: #ffd29a; box-shadow: 0 0 14px rgba(255, 183, 105, .95); }
body.ritual-lit .incense > i::after { opacity: 1; filter: blur(4px); }

.chat-header {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  color: #efe5d1;
  border-bottom: 0;
  background: linear-gradient(to bottom, rgba(12, 14, 12, .78), rgba(12, 14, 12, .18));
  backdrop-filter: blur(6px);
}
.chat-header > div { min-width: 0; text-align: center; }
.chat-header strong { display: block; font: 600 17px/1.3 var(--serif); }
.chat-header small { display: block; margin-top: 2px; color: rgba(239, 229, 209, .68); font: 11px/1.3 var(--sans); }
.chat-header .icon-button { color: #efe5d1; }
.scene-spacer { min-height: 0; pointer-events: none; }

.more-menu { position: absolute; top: calc(100% - 4px); right: max(14px, env(safe-area-inset-right)); z-index: 8; display: grid; min-width: 156px; overflow: hidden; border: 1px solid rgba(239,229,209,.17); border-radius: 8px; background: rgba(27, 28, 25, .96); box-shadow: 0 18px 48px rgba(0,0,0,.34); }
.more-menu button, .more-menu a { min-height: 46px; padding: 0 16px; color: #eee3cf; border: 0; border-bottom: 1px solid rgba(239,229,209,.1); background: transparent; text-align: left; text-decoration: none; font: 14px/46px var(--sans); cursor: pointer; }
.more-menu > :last-child { border-bottom: 0; }
.more-menu button:hover, .more-menu a:hover { background: rgba(255,255,255,.07); }

.icon-button, .round-button, .send-button, .attachment button { display: inline-grid; width: 40px; height: 40px; padding: 0; place-items: center; color: var(--ink); border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.icon-button:hover, .round-button:hover { background: rgba(45, 38, 31, .07); }
.icon { display: block; width: 20px; height: 20px; background: currentColor; mask-position: center; mask-repeat: no-repeat; mask-size: contain; -webkit-mask-position: center; -webkit-mask-repeat: no-repeat; -webkit-mask-size: contain; }
.icon-chevron-left { mask-image: url("/prototype-v03/assets/icons/chevron-left.svg"); -webkit-mask-image: url("/prototype-v03/assets/icons/chevron-left.svg"); }
.icon-ellipsis { mask-image: url("/prototype-v03/assets/icons/ellipsis.svg"); -webkit-mask-image: url("/prototype-v03/assets/icons/ellipsis.svg"); }
.icon-plus { mask-image: url("/prototype-v03/assets/icons/plus.svg"); -webkit-mask-image: url("/prototype-v03/assets/icons/plus.svg"); }
.icon-mic { mask-image: url("/prototype-v03/assets/icons/mic.svg"); -webkit-mask-image: url("/prototype-v03/assets/icons/mic.svg"); }
.icon-arrow-up { mask-image: url("/prototype-v03/assets/icons/arrow-up.svg"); -webkit-mask-image: url("/prototype-v03/assets/icons/arrow-up.svg"); }
.icon-square { mask-image: url("/prototype-v03/assets/icons/square.svg"); -webkit-mask-image: url("/prototype-v03/assets/icons/square.svg"); }
.icon-paperclip { mask-image: url("/prototype-v03/assets/icons/paperclip.svg"); -webkit-mask-image: url("/prototype-v03/assets/icons/paperclip.svg"); }
.icon-x { mask-image: url("/prototype-v03/assets/icons/x.svg"); -webkit-mask-image: url("/prototype-v03/assets/icons/x.svg"); }

.chat-stage { position: relative; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 30px max(18px, env(safe-area-inset-right)) 36px max(18px, env(safe-area-inset-left)); border-radius: 18px 18px 0 0; background: linear-gradient(rgba(71, 54, 34, .025) 1px, transparent 1px), linear-gradient(90deg, rgba(71, 54, 34, .025) 1px, transparent 1px), var(--paper); background-size: 52px 52px; box-shadow: 0 -10px 30px rgba(0,0,0,.24); }
.welcome { position: relative; display: grid; width: min(760px, 100%); margin: 0 auto; gap: 18px; align-content: start; }
.welcome p { max-width: 620px; margin: 0; color: var(--ink); font: 17px/1.85 var(--serif); }
.quiet-action { display: inline-flex; width: fit-content; align-items: center; gap: 10px; padding: 8px 2px 7px 0; color: #8b6a36; border: 0; border-bottom: 1px solid rgba(139,106,54,.38); background: transparent; font: 15px/1.2 var(--serif); cursor: pointer; }
.quiet-action:disabled { opacity: .55; cursor: default; }
.incense-mark { display: grid; width: 28px; height: 28px; place-items: center; border: 1px solid rgba(139,106,54,.4); border-radius: 50%; font-size: 12px; }
.thread { display: grid; width: min(760px, 100%); margin: 0 auto; }
.thread:empty { display: none; }
.message { position: relative; display: grid; margin: 12px 0 19px; animation: message-in 180ms ease-out; }
.message.user { justify-items: end; }
.message-content { max-width: min(680px, 88%); white-space: pre-wrap; }
.message.user .message-content { padding: 11px 16px; border-radius: 18px 18px 5px 18px; background: #e6ddd0; box-shadow: 0 4px 14px rgba(63,48,33,.04); }
.message.assistant .message-content { max-width: 100%; padding: 3px 0; font: 17px/1.85 var(--serif); }
.message p { margin: 0; }
.message-meta { margin-top: 7px; color: var(--muted); font: 11px/1.5 var(--sans); }
.message-action { margin-top: 12px; }
.receipt { margin-top: 10px; padding: 10px 12px; border-left: 2px solid #6f7b6f; background: rgba(255,255,255,.58); color: #514a42; font: 13px/1.6 var(--sans); }
.citation { margin-top: 12px; color: #5e554b; font: 12px/1.6 var(--sans); }
.citation summary { cursor: pointer; }
.draft-card { margin-top: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); font: 13px/1.6 var(--sans); }
.draft-card button, .draft-dialog > button { min-height: 42px; margin-top: 10px; padding: 0 16px; color: white; border: 0; border-radius: 6px; background: #394a40; cursor: pointer; }
.thinking { display: flex; gap: 4px; padding: 12px 0; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: #8b8379; animation: pulse 1.2s ease-in-out infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }

.composer-dock { position: relative; z-index: 5; padding: 8px max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); border-top: 0; background: rgba(246, 241, 231, .95); backdrop-filter: blur(18px); }
.composer, .attachment, .composer-status, .disclaimer { width: min(760px, 100%); margin-right: auto; margin-left: auto; }
.composer { padding: 9px 10px 8px; border: 1px solid rgba(47,39,31,.16); border-radius: 26px; background: var(--surface); box-shadow: 0 12px 32px rgba(44, 35, 27, .1); }
.composer textarea { display: block; width: 100%; min-height: 34px; max-height: 132px; padding: 5px 7px 2px; border: 0; outline: 0; color: var(--ink); background: transparent; resize: none; font: 16px/1.5 var(--sans); }
.composer-tools { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.composer-tools .record-time { margin-left: auto; }
.composer-tools .round-button:first-child { margin-right: auto; border: 1px solid var(--line); }
.send-button { color: #fff; background: #24211d; }
.round-button.recording { color: #fff; background: var(--cinnabar); }
.attachment { display: grid; grid-template-columns: 28px minmax(0,1fr) 34px; gap: 9px; align-items: center; margin-bottom: 7px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.attachment strong, .attachment small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment small { margin-top: 2px; color: var(--muted); }
.attachment button { width: 34px; height: 34px; }
.composer-status { margin-top: 0; margin-bottom: 6px; color: var(--cinnabar); text-align: center; font-size: 12px; }
.disclaimer { margin-top: 6px; margin-bottom: 0; color: #8a8278; text-align: center; font-size: 10px; }

.draft-dialog { width: min(620px, calc(100% - 28px)); max-height: 82dvh; padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 28px 90px rgba(0,0,0,.3); }
.draft-dialog::backdrop { background: rgba(18, 16, 13, .62); backdrop-filter: blur(4px); }
.draft-dialog header { display: flex; justify-content: space-between; gap: 16px; align-items: start; }
.draft-dialog h2 { margin: 4px 0 0; font: 600 22px/1.4 var(--serif); }
.draft-dialog small, .draft-dialog p { color: var(--muted); }
.draft-dialog pre { overflow: auto; max-height: 48dvh; padding: 14px; white-space: pre-wrap; border: 1px solid var(--line); background: #f7f2e8; font: 14px/1.7 var(--serif); }

@keyframes arrive { from { opacity: .38; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes smoke { 0% { opacity: 0; transform: translate(0, 5px) scaleX(.7) rotate(-3deg); } 24% { opacity: .8; } 65% { opacity: .36; transform: translate(12px, -70px) scaleX(1.25) rotate(8deg); } 100% { opacity: 0; transform: translate(-9px, -126px) scaleX(1.7) rotate(-8deg); } }
@keyframes pulse { 0%, 70%, 100% { opacity: .35; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }
@keyframes message-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

@media (max-width: 540px) {
  .stone-scene { padding: 0 14px; }
  .tablet { width: min(308px, 86vw); padding: 30px 24px 27px; }
  .portrait { width: 64px; height: 78px; margin: 4px auto 12px; }
  .tablet-name { font-size: 50px; }
  .tablet-years { margin-top: 10px; font-size: 11px; }
  .tablet-places { margin-top: 5px; font-size: 10px; }
  .tablet small { margin-top: 10px; font-size: 9px; }
  .incense { bottom: calc(50% - min(266px, 43vw)); }
  .memorial-chat { grid-template-rows: auto minmax(150px, 27dvh) minmax(0, 1fr) auto; }
  body.chat-open .stone-scene { height: 37dvh; }
  body.chat-open .tablet { bottom: -8px; left: 12px; width: 132px; padding: 16px 12px 13px; }
  body.chat-open .portrait { width: 34px; height: 41px; margin-bottom: 5px; }
  body.chat-open .tablet-name { font-size: 25px; }
  body.chat-open .incense { bottom: -3px; left: 63%; transform: translateX(-50%) scale(.58); }
  .chat-header { min-height: 58px; grid-template-columns: 40px minmax(0,1fr) 40px; padding-bottom: 7px; }
  .chat-stage { padding-top: 25px; padding-right: 20px; padding-left: 20px; border-radius: 16px 16px 0 0; }
  .welcome p, .message.assistant .message-content { font-size: 16px; }
  .message-content { max-width: 88%; }
  .disclaimer { display: none; }
  .composer-dock { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
