/* 记忆星河 · 深空主题（这是产品界面本身的设计语言，不是聊天主题） */

:root {
  --bg: #05060d;
  --bg-soft: #0b0e1a;
  --line: rgba(140, 170, 255, 0.14);
  --line-strong: rgba(140, 170, 255, 0.3);
  --text: #dfe6ff;
  --text-dim: #8b96b8;
  --accent: #79a7ff;
  --accent-soft: rgba(121, 167, 255, 0.16);
  --gold: #ffcf7a;

  --c-archive: #7fd7c4;
  --c-diary: #9db4ff;
  --c-memory: #a98bff;
  --c-event: #ff9d7a;
  --c-dialogue: #79cfef;
  --c-index: #c9b26b;
  --c-longform: #e894c6;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  transition: opacity 0.3s ease;
}
body.archive-mode #sky { opacity: 0; pointer-events: none; }
#sky.dragging { cursor: grabbing; }

/* ---------- 顶栏 ---------- */
#head {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  padding-top: calc(10px + var(--safe-top));
  background: linear-gradient(180deg, rgba(5, 6, 13, 0.97) 0%, rgba(5, 6, 13, 0.9) 72%, rgba(5, 6, 13, 0) 100%);
  backdrop-filter: blur(8px);
}

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.brand .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px 2px rgba(121, 167, 255, 0.85);
  animation: pulse 3.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.82); }
}

.search-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 380px;
}
#search {
  width: 100%;
  height: 34px;
  padding: 0 30px 0 12px;
  border-radius: 17px;
  border: 1px solid var(--line);
  background: rgba(12, 16, 30, 0.72);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
#search:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#search::placeholder { color: var(--text-dim); }
#search::-webkit-search-cancel-button { display: none; }

#search-clear {
  position: absolute;
  right: 6px; top: 5px;
  width: 24px; height: 24px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: none;
}
#search-clear.show { display: block; }

.views { display: flex; gap: 4px; margin-left: auto; flex: 0 0 auto; }
.view-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.18s;
}
.view-btn:hover { color: var(--text); }
.view-btn.active {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--accent-soft);
}

/* ---------- 分类 ---------- */
#kinds {
  padding: 0 14px 9px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
#kinds::-webkit-scrollbar { display: none; }

/* 角色行：和分类行区分开，用左边一道竖线做视觉分组 */
#scopes {
  padding: 0 14px 7px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  align-items: center;
}
#scopes::-webkit-scrollbar { display: none; }
#scopes:empty { display: none; }

.scope-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: rgba(11, 14, 26, 0.6);
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 11px;
  border-radius: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.scope-btn .n {
  opacity: .55;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}
.scope-btn:hover { color: var(--text); border-color: var(--line-strong, #2a3350); }
.scope-btn.active {
  color: #cfe0ff;
  border-color: rgba(120, 170, 255, 0.55);
  background: rgba(64, 108, 200, 0.22);
}
.scope-btn.active .n { opacity: .8; }
.scope-btn.unscoped { border-style: dashed; }

.scope-chip {
  color: #9fc0ff !important;
  border: 1px solid rgba(120, 170, 255, 0.35);
  border-radius: 8px;
  padding: 0 6px;
  font-size: 11px;
  opacity: .9;
}

.kind-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: rgba(11, 14, 26, 0.6);
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 11px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.16s;
  white-space: nowrap;
}
.kind-btn:hover { color: var(--text); border-color: var(--line-strong); }
.kind-btn.active {
  color: #060a16;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  left: 14px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 15;
  pointer-events: none;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.7;
}
#hud-stat { color: var(--text); opacity: 0.82; }
#hud-hint { opacity: 0.5; }

/* ---------- 详情 ---------- */
#detail {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  padding: calc(22px + var(--safe-top)) 22px calc(22px + var(--safe-bottom));
  background: rgba(8, 10, 20, 0.94);
  border-left: 1px solid var(--line);
  backdrop-filter: blur(18px);
  z-index: 30;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  overscroll-behavior: contain;
}
#detail.hidden { transform: translateX(102%); }

#detail-close {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 14px;
  width: 30px; height: 30px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
#detail-close:hover { color: var(--text); border-color: var(--line-strong); }

.detail-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.chip {
  padding: 2px 9px;
  border-radius: 9px;
  font-size: 11.5px;
  border: 1px solid currentColor;
  opacity: 0.9;
}

#detail-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.55;
  margin: 0 0 16px;
  padding-right: 30px;
  letter-spacing: 0.01em;
}

#detail-body {
  font-size: 14.5px;
  line-height: 2;
  color: #c8d2ee;
  white-space: pre-wrap;
  word-break: break-word;
}
#detail-body mark {
  background: rgba(255, 207, 122, 0.22);
  color: var(--gold);
  border-radius: 3px;
  padding: 0 2px;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.detail-actions button {
  flex: 1;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.16s;
}
.detail-actions button:hover { background: rgba(121, 167, 255, 0.26); }
.detail-actions button.on {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(255, 207, 122, 0.14);
}

/* ---------- 档案列表 ---------- */
#archive {
  position: fixed;
  inset: var(--head-h, 104px) 0 0 0;
  overflow-y: auto;
  padding: 4px 14px calc(90px + var(--safe-bottom));
  z-index: 18;
  background: var(--bg);
  overscroll-behavior: contain;
}
#archive.hidden { display: none; }

#archive-list { max-width: 760px; margin: 0 auto; }

.card {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(12, 16, 30, 0.92);
  padding: 13px 15px;
  margin-bottom: 9px;
  cursor: pointer;
  transition: border-color 0.16s, transform 0.16s, background 0.16s;
}
.card:hover {
  border-color: var(--line-strong);
  background: rgba(16, 20, 36, 0.9);
  transform: translateX(2px);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
}
.card-title {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-body {
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pin-mark { color: var(--gold); }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
  font-size: 13px;
  line-height: 2;
}

/* ---------- 口令闸门 ---------- */
#gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 40%, #10152b 0%, #05060d 70%);
  padding: 24px;
}
#gate.hidden { display: none; }

.gate-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}
.gate-title {
  font-size: 21px;
  letter-spacing: 0.2em;
  margin-bottom: 8px;
}
.gate-sub {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 0 0 22px;
  line-height: 1.7;
}
#gate-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(12, 16, 30, 0.8);
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 12px;
}
#gate-input:focus { border-color: var(--line-strong); }
#gate-btn {
  width: 100%;
  height: 42px;
  border-radius: 11px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #050912;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
#gate-btn:disabled { opacity: 0.5; cursor: default; }
#gate-err {
  margin-top: 12px;
  font-size: 12px;
  color: #ff8b8b;
  min-height: 16px;
}

.hidden { display: none; }

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  #topbar { flex-wrap: wrap; row-gap: 8px; padding-left: 10px; padding-right: 10px; }
  .brand { flex: 0 0 auto; }
  .brand-name { font-size: 13px; letter-spacing: 0.04em; }
  .search-wrap { order: 3; flex: 1 0 100%; max-width: none; }
  .views { margin-left: auto; }
  .view-btn { padding: 6px 10px; font-size: 12.5px; }
  #detail { width: 100vw; border-left: 0; top: 0; }
  #hud-hint { display: none; }
  #hud-stat {
    max-width: calc(100vw - 28px);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  #kinds { padding-left: 10px; padding-right: 10px; }
  #archive { padding-left: 10px; padding-right: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .brand .dot { animation: none; }
  #detail { transition: none; }
}
