/* 猫箱是纯暗色、图片铺满、信息压在半透明玻璃卡片上的观感，这里照着来。
   但采集到的字段比 App 显示的多，所以每个详情页都有一块「接口独有」的数据面板。 */

:root {
  --bg: #08080a;
  --bg-2: #0f0f12;
  --surface: rgba(255, 255, 255, .06);
  --surface-2: rgba(255, 255, 255, .09);
  --line: rgba(255, 255, 255, .1);
  --text: #f3f3f6;
  --muted: #9b9ba6;
  --dim: #6b6b78;
  --accent: #ffd76e;
  --hot: #ff6b81;
  --r: 16px;
  --rail: 92px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { display: block; max-width: 100%; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 4px; }

#app { display: flex; height: 100%; }
#view { flex: 1; min-width: 0; height: 100%; overflow-y: auto; overscroll-behavior: contain; }

/* ------------------------------------------------------------------ 侧栏 */

#rail {
  width: var(--rail); flex: none; background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 0;
}
.rail-brand {
  font-size: 11px; color: var(--muted); letter-spacing: .5px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 14px;
}
.rail-brand .dot {
  width: 24px; height: 24px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--hot));
}
#rail a {
  width: 68px; padding: 9px 0; border-radius: 12px; text-align: center;
  color: var(--dim); transition: background .15s, color .15s;
}
#rail a i { display: block; font-style: normal; font-size: 17px; line-height: 1.4; }
#rail a span { font-size: 11px; }
#rail a:hover { background: var(--surface); color: var(--muted); }
#rail a.on { background: var(--surface-2); color: var(--text); }
.rail-foot { margin-top: auto; font-size: 10px; color: var(--dim); text-align: center; padding: 0 6px; }

/* ------------------------------------------------------------------ 通用 */

.page { padding: 22px 26px 60px; max-width: 1500px; }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 21px; margin: 0; font-weight: 600; }
.page-head .count { color: var(--muted); font-size: 13px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar input[type=search], .toolbar select {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 7px 11px; outline: none; min-width: 0;
}
.toolbar input[type=search] { width: 240px; }
.toolbar input:focus, .toolbar select:focus { border-color: rgba(255,255,255,.3); }
.chip {
  padding: 6px 13px; border-radius: 999px; background: var(--surface);
  border: 1px solid transparent; color: var(--muted); font-size: 13px; white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: #fff; color: #111; font-weight: 600; }

.muted { color: var(--muted); }
.dim { color: var(--dim); }
.empty { padding: 60px 0; text-align: center; color: var(--dim); }
.spinner { padding: 60px 0; text-align: center; color: var(--dim); }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px;
  background: var(--surface-2); color: var(--muted);
}
.tag.hot { background: rgba(255,107,129,.16); color: #ff92a2; }
.tag.gold { background: rgba(255,215,110,.16); color: var(--accent); }

/* ------------------------------------------------------------------ 网格卡片 */

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(184px, 1fr));
}
.card {
  position: relative; border-radius: var(--r); overflow: hidden;
  background: var(--bg-2); aspect-ratio: 3 / 4.4; display: block;
  transition: transform .18s ease;
}
.card:hover { transform: translateY(-3px); }
.card > img { width: 100%; height: 100%; object-fit: cover; }
.card .noimg {
  width: 100%; height: 100%; display: grid; place-items: center;
  color: var(--dim); background: linear-gradient(160deg, #1a1a20, #101014);
}
.card .veil {
  position: absolute; inset: auto 0 0 0; padding: 30px 12px 11px;
  background: linear-gradient(to top, rgba(0,0,0,.92) 30%, transparent);
}
.card .veil .t, .card .veil .by { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .veil .t { font-weight: 600; font-size: 14px; }
.card .veil .m { display: flex; gap: 10px; font-size: 11.5px; color: #cfcfd8; margin-top: 3px; }
.card .veil .by { font-size: 11px; color: var(--dim); margin-top: 2px; }
.card .badges { position: absolute; top: 9px; left: 9px; display: flex; gap: 5px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ 沉浸流（照 App 首页） */

.feed { height: 100%; overflow-y: auto; scroll-snap-type: y mandatory; }
.feed-item {
  position: relative; height: 100%; scroll-snap-align: start;
  display: flex; justify-content: center; background: #000;
}
.feed-stage { position: relative; width: 100%; max-width: 480px; height: 100%; overflow: hidden; }
.feed-stage > img.bg { width: 100%; height: 100%; object-fit: cover; }
.feed-stage .shade {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.95) 12%, rgba(0,0,0,.7) 30%,
                              rgba(0,0,0,.15) 62%, rgba(0,0,0,.45));
}
.feed-body {
  position: absolute; inset: auto 0 0 0; padding: 0 16px calc(20px + var(--safe-b));
  display: flex; flex-direction: column; gap: 11px;
}
.feed-intro {
  background: rgba(20,20,24,.72); backdrop-filter: blur(14px);
  border-radius: 12px; padding: 11px 13px; font-size: 13.5px; line-height: 1.65;
  max-height: 7.6em; overflow: hidden; position: relative; cursor: pointer;
}
.feed-intro.open { max-height: 46vh; overflow-y: auto; }
.feed-intro .lead { color: var(--accent); }
/* 开场白气泡：App 里是浅色底、深色字，和其它面板反着来 */
.feed-open {
  background: rgba(244,244,248,.93); color: #17171b; border-radius: 14px;
  padding: 12px 14px; font-size: 13.5px; line-height: 1.7; max-height: 30vh; overflow-y: auto;
}
.feed-meta .n { font-size: 19px; font-weight: 600; }
.feed-meta .c { font-size: 12px; color: var(--muted); }
/* App 那排指标只给一个约数，位置照抄，但五个全摆出来 */
.feed-rail { display: flex; justify-content: space-between; gap: 6px; text-align: center; }
.feed-rail .it { flex: 1; min-width: 0; }
.feed-rail .it .v { font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.feed-rail .it .k { font-size: 10px; color: var(--muted); }
.feed-actions { display: flex; gap: 8px; }
.feed-actions .btn {
  flex: 1; text-align: center; padding: 11px; border-radius: 999px;
  background: rgba(255,255,255,.12); backdrop-filter: blur(10px); font-size: 13px;
}
.feed-actions .btn.primary { background: #fff; color: #111; font-weight: 600; }
.feed-top {
  position: absolute; top: 0; left: 0; right: 0; padding: 14px 16px;
  display: flex; gap: 8px; align-items: center; font-size: 12px; color: rgba(255,255,255,.75);
  background: linear-gradient(to bottom, rgba(0,0,0,.55), transparent);
}

/* ------------------------------------------------------------------ 详情 */

.hero { position: relative; min-height: 440px; display: flex; align-items: flex-end; }
/* 裁切保持居中：立绘的构图不统一（story 的 cover 和 character 的 background 框得不一样），
   试过把锚点上提，有的露脸了有的只剩帽子，居中反而两边都还行 */
.hero > img.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero .shade {
  position: absolute; inset: 0;
  background: linear-gradient(to top, var(--bg) 2%, rgba(8,8,10,.55) 45%, rgba(8,8,10,.25));
}
.hero-in { position: relative; padding: 26px; width: 100%; }
.hero-in h1 { font-size: 30px; margin: 0 0 6px; font-weight: 600; }
.hero-by { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.hero-by img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }

/* 五个指标一排铺开——README 反复强调这五个互不等价，不能只显示一个 */
.metrics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.metric {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 15px; min-width: 96px;
}
.metric .v { font-size: 18px; font-weight: 600; }
.metric .k { font-size: 11px; color: var(--muted); }
.metric .sub { font-size: 10px; color: var(--dim); }

.panels { padding: 22px 26px 70px; display: grid; gap: 16px; max-width: 1500px; }
.panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.panel > h2 {
  margin: 0; padding: 13px 18px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center;
}
.panel > h2 .note { font-weight: 400; color: var(--dim); font-size: 11px; }
.panel-in { padding: 16px 18px; }
.prose { white-space: pre-wrap; line-height: 1.8; font-size: 13.5px; }

/* 字段表：所有采到的原子字段都在这儿，不挑不藏 */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 7px 18px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.kv dd code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.swatches { display: flex; gap: 14px; flex-wrap: wrap; }
.swatch { text-align: center; font-size: 10px; color: var(--muted); }
.swatch .box { width: 54px; height: 40px; border-radius: 8px; border: 1px solid var(--line); }

.chars { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.char {
  display: flex; gap: 12px; background: var(--surface); border-radius: 12px; padding: 12px;
}
.char .pic { width: 62px; height: 82px; border-radius: 9px; object-fit: cover; flex: none; background: #16161b; }
.char .n { font-weight: 600; }
.char .meta { font-size: 12px; color: var(--muted); }
.char .prompt {
  margin-top: 8px; font-size: 12px; line-height: 1.7; color: #d3d3dc; white-space: pre-wrap;
  max-height: 8.5em; overflow-y: auto; background: rgba(0,0,0,.28); border-radius: 8px; padding: 8px 10px;
}

.assets { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.asset { font-size: 10.5px; color: var(--dim); }
/* portrait 类素材是抠好的透明人像，铺在深色底上等于看不见，垫一层棋盘格 */
.asset img {
  width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 9px;
  background-color: #6a6a72;
  background-image: linear-gradient(45deg, #55555c 25%, transparent 25%, transparent 75%, #55555c 75%),
                    linear-gradient(45deg, #55555c 25%, transparent 25%, transparent 75%, #55555c 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}
.asset .r { color: var(--muted); margin-top: 4px; }

details.raw > summary { cursor: pointer; color: var(--muted); font-size: 12px; }
pre.json {
  margin: 10px 0 0; padding: 12px; background: #000; border-radius: 10px; max-height: 460px;
  overflow: auto; font-size: 11.5px; line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: #b9c7d6;
}

/* ------------------------------------------------------------------ 会话 */

.chat { display: flex; flex-direction: column; height: 100%; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.chat-head img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.chat-log { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.bubble {
  max-width: 620px; padding: 12px 15px; border-radius: 16px; line-height: 1.75;
  font-size: 13.5px; white-space: pre-wrap;   /* 介绍里的换行是内容的一部分，别吃掉 */
}
.bubble.them { background: rgba(244,244,248,.93); color: #17171b; border-bottom-left-radius: 5px; }
.bubble.me { background: #2b2b33; align-self: flex-end; border-bottom-right-radius: 5px; }
.bubble .who { font-size: 11px; color: var(--dim); margin-bottom: 3px; }
.chat-input {
  display: flex; gap: 10px; padding: 14px 18px calc(14px + var(--safe-b));
  border-top: 1px solid var(--line); background: var(--bg-2);
}
.chat-input input {
  flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 11px 18px; color: var(--text); outline: none;
}
.chat-input input:disabled { color: var(--dim); }
.chat-note { text-align: center; font-size: 12px; color: var(--dim); padding: 8px 0 0; }

/* 括号内是动作/神态/内心，括号外才是说出口的话——猫箱最标志性的排版，
   调暗一档，一眼能分开。见 chat.js:fmt() */
.bubble .act { color: rgba(23,23,27,.52); }
.bubble.narr .act, .bubble.intro .act { color: inherit; opacity: .8; }

/* 旁白没有说话人，不做成气泡，居中压暗，和角色台词区分开 */
.bubble.narr {
  align-self: center; max-width: 680px; background: rgba(255,255,255,.05);
  color: var(--muted); border-radius: 12px; font-size: 13px;
}
.bubble.intro {
  align-self: center; max-width: 680px; background: rgba(255,255,255,.07);
  color: var(--muted); border-radius: 12px; font-size: 12.5px;
}

/* 「当前目标」横幅：猫箱是钉在立绘上的一条，这里钉在消息区顶上 */
.goal-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px; font-size: 12.5px; color: var(--muted);
  background: rgba(255,255,255,.045); border-bottom: 1px solid var(--line);
}
.goal-bar b {
  font-size: 11px; color: var(--bg); background: var(--accent, #f5d24a);
  border-radius: 5px; padding: 2px 7px; font-weight: 700; flex: none;
}
.goal-bar[hidden] { display: none; }

.chapter-mark {
  align-self: center; font-size: 11.5px; color: var(--dim);
  letter-spacing: .12em; padding: 6px 0;
}

/* ------------------------------------------------------------------ 数据页 */

.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.stat {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
}
.stat .v { font-size: 25px; font-weight: 600; }
.stat .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 150px 1fr max-content; gap: 10px; align-items: center; font-size: 12.5px; }
.bar .track { height: 8px; background: var(--surface); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--hot)); }
.bar .lbl { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ 移动端：侧栏变底部 tab */

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  #rail {
    width: 100%; flex-direction: row; justify-content: space-around; padding: 6px 0 var(--safe-b);
    border-right: 0; border-top: 1px solid var(--line);
  }
  .rail-brand, .rail-foot { display: none; }
  #rail a { width: auto; flex: 1; }
  .page, .panels { padding: 16px 14px 40px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .hero { min-height: 68vh; }
  .toolbar input[type=search] { width: 100%; }
}

/* ------------------------------------------------------------------ 身份 / 历史 / 参演 */

.signin { max-width: 420px; margin: 14vh auto; padding: 0 24px; }
.signin h2 { margin: 0 0 6px; font-size: 20px; }
.signin p { margin: 0 0 18px; font-size: 13px; line-height: 1.7; }
.signin-row { display: flex; gap: 10px; margin-bottom: 8px; }
.signin-row input {
  flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 11px 18px; color: var(--text); outline: none;
}

.rail-user {
  margin-top: auto; padding: 10px 6px; font-size: 11px; color: var(--muted);
  text-align: center; line-height: 1.7; word-break: break-all;
}
.rail-user a { display: block; color: var(--dim); font-size: 10.5px; }

.hist-list { display: flex; flex-direction: column; gap: 10px; }
.hist {
  display: flex; gap: 12px; padding: 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg-2); color: inherit;
}
.hist:hover { border-color: var(--dim); }
.hist-cover { width: 56px; height: 76px; object-fit: cover; border-radius: 8px; flex: none; }
.hist-body { min-width: 0; flex: 1; }
.hist-title { font-weight: 600; margin-bottom: 3px; }
.hist-last {
  font-size: 12.5px; color: var(--muted); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.hist-meta { font-size: 11px; margin-top: 5px; }

.rel-h { font-size: 12px; color: var(--dim); margin: 12px 0 6px; }
.rel-h:first-child { margin-top: 0; }
.rel {
  display: flex; flex-direction: column; gap: 2px; padding: 9px 12px; margin-bottom: 6px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: inherit;
}
a.rel:hover { border-color: var(--dim); }
.rel-n { font-size: 13px; }
.rel .dim { font-size: 11.5px; }

/* 会话页的背景立绘：铺满整页压在气泡后面，换章会换图 */
.chat { position: relative; }
.chat-bg {
  position: absolute; inset: 0; z-index: 0;
  background-size: cover; background-position: center top;
  opacity: .3; filter: saturate(.85);
  transition: background-image .4s ease;
  pointer-events: none;
}
.chat-head, .goal-bar, .chat-log, .chat-input { position: relative; z-index: 1; }

/* rail-foot 原本用 margin-top:auto 顶到底，现在底部多了个用户块，
   改成让用户块负责顶，否则两个 auto 会把空间对半分。 */
.rail-foot { margin-top: 6px; }
.chip.danger { background: rgba(224,113,111,.2); color: #ff9c9a; }
