﻿/* ---------- 主题变量 ---------- */
:root{
  /* 告诉浏览器：这个页面本来就是深色的。
     不写这一行，安卓/Chrome 的「强制深色模式」会把浅色气泡反成黑色块 */
  color-scheme: dark;
  --bg:#080b16;
  --bg2:#0f1730;
  --wall:#121a33;
  --ink:#e9edff;
  --muted:#8e97b8;
  --line:rgba(255,255,255,.08);
  --blue:#4da3ff;
  --blue-dim:#2b6bb8;
  --orange:#ff9f43;
  --her-bg:#f3f6ff;
  --her-ink:#1a2140;
  --me-bg:#2a3a66;
  --me-ink:#e2e9ff;
  --radius:18px;
  --safe-b:env(safe-area-inset-bottom, 0px);
}

*{box-sizing:border-box; -webkit-tap-highlight-color:transparent}
html,body{height:100%;margin:0}
body{
  background:#05070f;
  font-family:"PingFang SC","Microsoft YaHei","Noto Sans SC",system-ui,sans-serif;
  color:var(--ink);
  display:flex; align-items:center; justify-content:center;
  overflow:hidden;
}

/* 手机画布 375x812，桌面居中 */
#app{
  position:relative;
  width:min(100vw, 430px);
  height:100vh;
  max-height:900px;
  overflow:hidden;
  background:var(--bg);
  display:flex; flex-direction:column;
}
@media (min-width:520px){
  #app{
    width:430px; height:860px;
    border-radius:28px;
    box-shadow:0 30px 80px rgba(0,0,0,.7), 0 0 0 1px rgba(255,255,255,.06);
  }
}

/* ---------- 房间 ---------- */
.room{position:absolute; inset:0; overflow:hidden}
/* 两层交叉淡入：换时段时新图淡入、旧图淡出，不会黑一下 */
.wall{
  position:absolute; inset:0;
  background:url("assets/room-night.jpg") center/cover no-repeat;
  transform:scale(1.02);
  opacity:1;
  transition:opacity 1.15s ease;
}
.wall-next{opacity:0}
/* 时段对灯具、暗角的影响（图已经调过色，这里再补一点环境感） */
html[data-period="day"] .lamp{opacity:.22}
html[data-period="morning"] .lamp{opacity:.38}
html[data-period="evening"] .lamp{opacity:.78}
html[data-period="night"] .lamp{opacity:1}
html[data-period="day"] .vignette{opacity:.55}
html[data-period="morning"] .vignette{opacity:.72}
html[data-period="evening"] .vignette{opacity:.95}
html[data-period="night"] .vignette{opacity:1}
/* 她本人的受光也要跟房间一致，否则白天里像贴上去的 */
.stage{transition:filter 1.1s ease}
html[data-period="morning"] .stage{filter:brightness(1.00) saturate(.95) hue-rotate(-5deg)}
html[data-period="day"]     .stage{filter:brightness(1.06) saturate(.95) contrast(1.01)}
html[data-period="evening"] .stage{filter:brightness(1.02) saturate(1.10) sepia(.14)}
html[data-period="night"]   .stage{filter:brightness(.93) saturate(1.03)}
/* 窗：现在是照片里的窗，只保留"亮起"的光效 */
.window{
  position:absolute; left:2%; top:3%;
  width:46%; height:40%;
  border-radius:6px;
  overflow:visible;
  border:0;
  background:transparent;
  box-shadow:none;
  transition:box-shadow .6s ease, filter .6s ease;
}
.sky,.stars,.city,.frame{display:none}
/* 书架、灯光：照片里已有，隐藏手绘的 */
.shelf{display:none}
.lamp{
  position:absolute; right:-8%; bottom:2%;
  width:70%; height:55%;
  background:radial-gradient(circle at 70% 65%, rgba(255,178,90,.16), transparent 64%);
  filter:blur(8px);
  animation:lampPulse 5s ease-in-out infinite alternate;
  pointer-events:none;
}
.vignette{
  position:absolute; inset:0;
  background:
    linear-gradient(180deg, rgba(4,6,12,.55) 0%, rgba(4,6,12,0) 18%),
    radial-gradient(120% 90% at 50% 40%, transparent 42%, rgba(0,0,0,.6) 100%);
  pointer-events:none;
}

/* ---------- 立绘 ---------- */
.stage{
  position:absolute; left:0; right:0; bottom:0;
  height:78%;
  display:flex; align-items:flex-end; justify-content:center;
  pointer-events:none;
}
/* 外层：缓慢左右摆动（呼吸之外的"活着"感） */
.sway{
  height:100%;
  display:flex; align-items:flex-end; justify-content:center;
  transform-origin:50% 96%;
  animation:sway 7.6s ease-in-out infinite;
  will-change:transform;
}
#figure{
  height:112%; width:auto; object-fit:contain;
  transform-origin:50% 100%;
  animation:breathe 5.4s ease-in-out infinite;
  filter:drop-shadow(0 12px 24px rgba(0,0,0,.45));
  opacity:0; transition:opacity .8s ease;
  margin-bottom:-14%;
  backface-visibility:hidden;
}
/* Live2D 画布：和立绘同位置 */
#live2d{
  display:block;
  width:100%; height:100%;
  margin-bottom:-2%;
}
#figure.gone{display:none}
#figure.ready{opacity:1}
/* 脚下接触阴影：让她站进画面，而不是浮着 */
.shadow{
  position:absolute; bottom:1%; left:50%; transform:translateX(-50%);
  width:38%; height:3.4%;
  background:radial-gradient(ellipse at center, rgba(0,0,0,.6), transparent 72%);
  filter:blur(7px);
  animation:shadowPulse 5.4s ease-in-out infinite;
}

/* ---------- 顶部 ---------- */
.hud{
  position:relative; z-index:3;
  padding:calc(14px + env(safe-area-inset-top,0px)) 18px 10px;
  background:linear-gradient(180deg, rgba(6,9,18,.88) 0%, rgba(6,9,18,.45) 65%, rgba(6,9,18,0) 100%);
  backdrop-filter:blur(2px);
  display:grid; grid-template-columns:1fr auto; gap:6px 10px;
  text-shadow:0 1px 8px rgba(0,0,0,.65);
}
.who{display:flex; align-items:center; gap:8px}
.name{font-size:17px; font-weight:600; letter-spacing:.5px}
.badge{
  font-size:11px; padding:2px 8px; border-radius:99px;
  color:var(--blue); background:rgba(20,34,62,.55);
  border:1px solid rgba(77,163,255,.32);
  box-shadow:0 2px 10px rgba(0,0,0,.25);
}
.meta{font-size:11px; color:var(--muted); align-self:center;
  display:flex; align-items:center; gap:8px; justify-content:flex-end}
/* 时段切换：默认跟随手机时间，点一下可锁定 */
.period[hidden]{display:none}
.period{
  width:22px; height:22px; flex:0 0 auto;
  padding:0; border-radius:50%;
  border:1px solid rgba(255,255,255,.16);
  background:rgba(20,28,50,.55);
  font-size:12px; line-height:1;
  display:grid; place-items:center;
  color:var(--ink); cursor:pointer;
  transition:border-color .2s ease, box-shadow .2s ease;
}
.period:active{transform:scale(.92)}
.period.manual{
  border-color:rgba(77,163,255,.55);
  box-shadow:0 0 0 2px rgba(77,163,255,.14);
}
.affinity{
  grid-column:1 / -1;
  height:3px; border-radius:99px; background:rgba(255,255,255,.08);
  overflow:hidden;
}
.affinity i{
  display:block; height:100%;
  background:linear-gradient(90deg,var(--blue),var(--orange));
  border-radius:99px; transition:width .8s ease;
}

/* ---------- 对话 ---------- */.chat{
  position:relative; z-index:2; flex:1;
  overflow-y:auto; overflow-x:hidden;
  padding:8px 18px 12px;
  scrollbar-width:none;
  mask-image:linear-gradient(180deg, transparent 0, #000 22px);
  -webkit-mask-image:linear-gradient(180deg, transparent 0, #000 22px);
}
.chat::-webkit-scrollbar{display:none}
/* 消息少的时候贴着底部（不挡她的脸），多了自然往上滚 */
.list{
  display:flex; flex-direction:column;
  gap:14px;                 /* 组与组之间留白，一屏别塞太满 */
  padding-bottom:14px;
  min-height:100%;
  justify-content:flex-end;
}
/* 同一个人连着说：收紧间距，读起来是一个整体 */
.msg.cont{margin-top:-8px}

.msg{display:flex; max-width:100%; animation:rise .24s cubic-bezier(.22,.7,.3,1) both}
.msg .bubble{
  max-width:76%;
  /* 兜底：某些国产/老内核浏览器里 flex 子项不会自动收缩，气泡会被撑满整行 */
  width:fit-content;
  padding:11px 15px;
  font-size:15px; line-height:1.7; letter-spacing:.1px;
  border-radius:20px;
  word-break:break-word;
  white-space:pre-wrap;
  position:relative;
}
/* 她的动作描写（括号内容）弱化成旁白，别跟台词一样重 */
.msg .bubble .act{
  color:#6b7699;
  font-style:italic;
  font-size:.93em;
  opacity:.92;
}
.msg.me .bubble .act{color:rgba(226,233,255,.72)}
.msg.her{justify-content:flex-start}
/* 层次靠明度和投影，不靠描边 */
.msg.her .bubble{
  background:linear-gradient(180deg, rgba(253,254,255,.97) 0%, rgba(240,244,255,.97) 100%);
  color:var(--her-ink);
  border-bottom-left-radius:8px;
  box-shadow:0 6px 20px -6px rgba(0,0,0,.45);
}
.msg.me{justify-content:flex-end}
.msg.me .bubble{
  background:linear-gradient(180deg, rgba(50,68,116,.96) 0%, rgba(38,53,92,.97) 100%);
  color:var(--me-ink);
  border-bottom-right-radius:8px;
  box-shadow:0 6px 20px -6px rgba(0,0,0,.5);
}
.msg.sys{justify-content:center}
.msg.sys .bubble{
  background:rgba(255,255,255,.04); color:var(--muted);
  font-size:12px; padding:5px 12px; border-radius:99px;
}
/* 历史分隔线：下面是上次聊的，上面是这次接的 */
.msg.divider-row{justify-content:center; margin:4px 0}
.divider{
  font-size:11px; color:rgba(158,168,198,.9);
  letter-spacing:.4px;
  display:flex; align-items:center; gap:12px;
  width:100%;
}
.divider span{
  background:rgba(10,14,24,.46);
  padding:2px 11px; border-radius:99px;
  backdrop-filter:blur(6px);
  white-space:nowrap;
  text-shadow:0 1px 6px rgba(0,0,0,.55);
}
.divider::before, .divider::after{
  content:""; flex:1; height:1px;
  background:linear-gradient(90deg, transparent, rgba(255,255,255,.12), transparent);
}

/* 打字中 */
.typing .bubble{display:flex; gap:5px; align-items:center; padding:14px 16px}
.typing i{
  width:6px;height:6px;border-radius:50%;
  background:var(--her-ink); opacity:.55;
  animation:blink 1.2s infinite;
}
.typing i:nth-child(2){animation-delay:.18s}
.typing i:nth-child(3){animation-delay:.36s}

/* 她在想：微光文字（Claude 桌面版那种流动感） */
.msg.thinking-row{justify-content:flex-start}
.thinking-shimmer{
  display:flex; align-items:center; gap:7px;
  padding:5px 2px;
  font-size:13px; color:var(--muted);
}
.thinking-shimmer .spark{
  color:var(--blue); font-size:11px;
  animation:sparkle 1.6s ease-in-out infinite;
}
.shimmer-text{
  background:linear-gradient(100deg,
    rgba(150,162,196,.45) 0%,
    rgba(220,230,255,.95) 45%,
    rgba(150,162,196,.45) 70%);
  background-size:220% 100%;
  -webkit-background-clip:text; background-clip:text;
  color:transparent;
  animation:shimmer 2.1s linear infinite;
}

/* 动作描写 */
.msg.action-row{justify-content:flex-start}
.action{
  font-size:12.5px; color:rgba(196,206,230,.95);
  /* 旁白没有底色，压在浅色头发/亮窗上也要读得清 */
  text-shadow:0 1px 10px rgba(0,0,0,.9), 0 0 3px rgba(0,0,0,.75);
  padding:2px 4px 3px 4px;
  animation:rise .3s ease both;
}

/* 打字机：文字末尾加一个细光标 */
.bubble.typing-text::after{
  content:"";
  display:inline-block; width:2px; height:1em;
  margin-left:2px; vertical-align:-2px;
  background:currentColor; opacity:.45;
  animation:caret .9s steps(1) infinite;
}

/* 思考中状态条 */
.msg.think{justify-content:flex-start}
.thinkline{
  display:flex; align-items:center; gap:7px;
  font-size:13px; color:var(--muted);
  padding:6px 4px;
}
.thinkline .spark{
  color:var(--blue); font-size:12px;
  animation:sparkle 1.6s ease-in-out infinite;
}
.ellipsis{display:inline-flex; gap:1px}
.ellipsis i{
  font-style:normal; opacity:.25;
  animation:blink 1.4s infinite;
}
.ellipsis i:nth-child(2){animation-delay:.2s}
.ellipsis i:nth-child(3){animation-delay:.4s}

/* 思考了 N 次（可展开） */
.msg.thought{flex-direction:column; align-items:flex-start; gap:4px}
.thought-head{
  display:flex; align-items:center; gap:6px;
  background:none; border:0; padding:2px 2px;
  color:var(--muted); font-size:12px; cursor:pointer;
  font-family:inherit;
}
.thought-head .spark{color:var(--blue); font-size:11px}
.thought-head .chev{
  transition:transform .2s ease; display:inline-block;
}
.msg.thought.open .thought-head .chev{transform:rotate(90deg)}
.thought-body{
  font-size:12.5px; line-height:1.7;
  color:var(--muted);
  padding:8px 12px;
  background:rgba(255,255,255,.035);
  border-left:2px solid rgba(77,163,255,.35);
  border-radius:8px;
  max-width:86%;
  white-space:pre-wrap;
}

/* ---------- 输入 ---------- */
.composer{
  position:relative; z-index:4;
  display:flex; align-items:center; gap:8px;
  padding:10px 16px calc(14px + var(--safe-b));
  background:linear-gradient(180deg, rgba(6,9,18,0) 0%, rgba(6,9,18,.68) 42%, rgba(6,9,18,.93) 100%);
  backdrop-filter:blur(3px);
}
.icon{
  width:38px;height:38px;flex:0 0 auto;
  border-radius:50%;
  border:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.055);
  color:var(--ink); font-size:16px;
  display:grid; place-items:center;
}
.icon.off{opacity:.4}
#input{
  flex:1; min-width:0;
  height:44px; padding:0 18px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.08);
  background:rgba(255,255,255,.055);
  color:var(--ink); font-size:15px;
  outline:none;
  transition:border-color .2s ease, background .2s ease, box-shadow .2s ease;
}
#input::placeholder{color:rgba(142,151,184,.8)}
#input:focus{
  border-color:rgba(77,163,255,.36);
  background:rgba(255,255,255,.075);
  box-shadow:0 0 0 3px rgba(77,163,255,.08);
}
.send{
  width:42px;height:42px;flex:0 0 auto;
  border-radius:50%; border:none;
  background:linear-gradient(135deg,var(--blue),#2f7fe0);
  color:#fff; font-size:16px;
  display:grid; place-items:center;
  box-shadow:0 6px 18px -4px rgba(77,163,255,.55);
}
.send:active{transform:scale(.94)}

/* ---------- 窗亮起（有新消息） ---------- */
.window.alert{
  box-shadow:0 0 0 6px rgba(255,255,255,.10),
             0 0 70px rgba(255,159,67,.55),
             0 0 140px rgba(255,159,67,.25);
  filter:saturate(1.15) brightness(1.15);
  animation:windowPulse 2.4s ease-in-out infinite;
}

/* ---------- toast ---------- */
.toast{
  position:absolute; left:50%; top:64px; transform:translateX(-50%);
  z-index:9; padding:8px 16px; border-radius:99px;
  background:rgba(10,16,30,.92); border:1px solid var(--line);
  font-size:13px; color:var(--ink);
}

/* ---------- 登录 ---------- */
.login{
  position:absolute; inset:0; z-index:20;
  display:grid; place-items:center;
  background:radial-gradient(120% 90% at 50% 30%, rgba(20,30,60,.65), rgba(4,6,12,.94));
  backdrop-filter:blur(6px);
}
/* hidden 必须能盖住 display:grid */
.login[hidden]{display:none}
.toast[hidden]{display:none}
.login-card{
  width:78%; max-width:300px;
  display:flex; flex-direction:column; gap:12px;
  padding:26px 22px 22px;
  border-radius:22px;
  background:rgba(14,20,38,.92);
  border:1px solid rgba(120,160,255,.16);
  box-shadow:0 24px 60px rgba(0,0,0,.6);
}
.login-title{
  font-size:22px; font-weight:600; letter-spacing:3px;
  text-align:center; color:var(--ink);
}
.login-sub{
  font-size:12px; text-align:center; color:var(--muted);
  margin-bottom:6px; letter-spacing:1px;
}
.login-card input{
  height:44px; padding:0 14px; border-radius:12px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(255,255,255,.05);
  color:var(--ink); font-size:15px; outline:none;
  font-family:inherit;
}
.login-card input:focus{border-color:rgba(77,163,255,.5)}
.login-card button{
  height:46px; border-radius:12px; border:none;
  background:linear-gradient(135deg,var(--blue),#2f7fe0);
  color:#fff; font-size:15px; letter-spacing:2px;
  font-family:inherit; cursor:pointer;
  box-shadow:0 10px 24px rgba(77,163,255,.3);
}
.login-card button:disabled{opacity:.6}
.login-err{
  font-size:12.5px; color:#ff8d8d; text-align:center;
}

/* ---------- 动画 ---------- */
@keyframes breathe{
  0%,100%{transform:translateY(0) scaleY(1)}
  45%{transform:translateY(-3px) scaleY(1.004)}
  70%{transform:translateY(-1px) scaleY(1.002)}
}
@keyframes sway{
  0%,100%{transform:translateX(-1.5px) rotate(-0.18deg)}
  50%{transform:translateX(2px) rotate(0.22deg)}
}
@keyframes shadowPulse{
  0%,100%{opacity:.9; transform:translateX(-50%) scaleX(1)}
  50%{opacity:.7; transform:translateX(-50%) scaleX(1.04)}
}
@keyframes twinkle{from{opacity:.55} to{opacity:1}}
@keyframes lampPulse{from{opacity:.75} to{opacity:1}}
@keyframes rise{from{opacity:0; transform:translateY(8px)} to{opacity:1; transform:none}}
@keyframes blink{0%,80%,100%{opacity:.25; transform:translateY(0)} 40%{opacity:1; transform:translateY(-2px)}}
@keyframes windowPulse{
  0%,100%{filter:saturate(1.15) brightness(1.12)}
  50%{filter:saturate(1.3) brightness(1.3)}
}
@keyframes sparkle{
  0%,100%{opacity:.55; transform:scale(.9) rotate(0deg)}
  50%{opacity:1; transform:scale(1.1) rotate(15deg)}
}
@keyframes floatDot{
  0%,100%{transform:translateY(0)}
  50%{transform:translateY(-4px)}
}
@keyframes shimmer{
  0%{background-position:120% 0}
  100%{background-position:-120% 0}
}
@keyframes caret{
  0%,49%{opacity:.45}
  50%,100%{opacity:0}
}

/* 减少动效 */
@media (prefers-reduced-motion: reduce){
  #figure{animation:none}
  .stars{animation:none}
  .lamp{animation:none}
  .window.alert{animation:none}
}

/* ---------- 主人视角（T2 多用户） ---------- */
.admin{
  position:absolute; inset:0; z-index:30;
  display:flex; align-items:center; justify-content:center;
  padding:16px;
  background:rgba(4,6,14,.66);
  backdrop-filter:blur(6px);
}
.admin[hidden]{display:none}
.admin-card{
  width:100%; max-height:100%;
  display:flex; flex-direction:column;
  background:rgba(12,16,28,.96);
  border:1px solid var(--line);
  border-radius:20px;
  box-shadow:0 24px 60px rgba(0,0,0,.55);
  overflow:hidden;
}
.admin-top{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px; border-bottom:1px solid var(--line);
}
.admin-title{font-size:14px; letter-spacing:.06em; color:var(--ink); font-weight:600}
.admin-close{background:none;border:0;color:var(--muted);font-size:15px;cursor:pointer;padding:4px 8px;border-radius:8px}
.admin-close:hover{background:rgba(255,255,255,.06); color:var(--ink)}
.admin-scroll{overflow:auto; padding:12px 14px 16px; display:flex; flex-direction:column; gap:12px}
.admin-users{display:flex; flex-direction:column; gap:8px}
.admin-user{
  display:flex; align-items:center; gap:10px;
  padding:10px 12px; border-radius:12px;
  background:rgba(255,255,255,.035);
  border:1px solid var(--line);
  cursor:pointer;
}
.admin-user:hover{background:rgba(255,255,255,.07)}
.admin-user .who{flex:1; min-width:0}
.admin-user .nm{font-size:14px; color:var(--ink); overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.admin-user .sub{font-size:11px; color:var(--muted); margin-top:3px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.admin-user .role{flex:none; font-size:10px; padding:2px 8px; border-radius:999px; border:1px solid var(--line); color:var(--muted)}
.admin-user .role.owner{color:#ffd28a; border-color:rgba(255,210,138,.35)}
.admin-user .role.friend{color:#9ecbff; border-color:rgba(158,203,255,.3)}
.admin-history{display:flex; flex-direction:column; gap:8px; border-top:1px solid var(--line); padding-top:12px}
.admin-hist-head{font-size:12px; color:var(--muted)}
.admin-empty{font-size:12px; color:var(--muted)}
.admin-msg{font-size:13px; line-height:1.55; display:flex; gap:8px}
.admin-msg .admin-who{flex:none; font-size:11px; color:var(--muted); padding-top:2px; min-width:2.4em}
.admin-msg.her .admin-text{color:var(--ink)}
.admin-msg.me .admin-text{color:rgba(233,237,255,.78)}
.admin-msg.me .admin-who{color:#9ecbff}
.admin-actions{margin-top:2px}
.admin-btn{
  width:100%; padding:11px 14px; border-radius:12px; border:1px solid var(--line);
  background:rgba(77,163,255,.16); color:var(--ink); font-size:13px; cursor:pointer;
}
.admin-btn:hover{background:rgba(77,163,255,.26)}
.admin-btn.ghost{background:transparent; color:var(--muted)}
.admin-btn.ghost:hover{background:rgba(255,255,255,.06); color:var(--ink)}
.admin-add{display:flex; flex-direction:column; gap:10px; border-top:1px solid var(--line); padding-top:12px}
.admin-add-title{font-size:12px; color:var(--muted)}
.admin-add-grid{display:flex; flex-direction:column; gap:8px}
.admin-add input{
  width:100%; padding:10px 12px; border-radius:10px;
  border:1px solid var(--line); background:rgba(255,255,255,.04); color:var(--ink); font-size:13px;
}
.admin-add input:focus{outline:none; border-color:rgba(77,163,255,.55); background:rgba(255,255,255,.06)}
