:root {
  color-scheme: light;
  --bg: #f5f1eb;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #fffdf9;
  --ink: #20201f;
  --muted: #77736d;
  --line: rgba(50, 45, 39, 0.1);
  --accent: #8d2637;
  --accent-deep: #641726;
  --accent-soft: #f1dfe2;
  --sage: #75827c;
  --shadow: 0 22px 60px rgba(51, 38, 32, 0.1);
  --radius: 28px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 2%, rgba(204, 151, 144, 0.15), transparent 26rem),
    radial-gradient(circle at 92% 18%, rgba(118, 137, 127, 0.12), transparent 24rem),
    var(--bg);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.58; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 0 22px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(32, 32, 31, 0.055);
}

.auth-tabs button {
  min-height: 40px;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
}

.auth-tabs button.active {
  color: var(--accent);
  background: var(--surface-solid);
  box-shadow: 0 4px 16px rgba(51, 38, 32, 0.08);
}

.ambient {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(1px);
  pointer-events: none;
}

.ambient-one {
  width: 28rem;
  height: 28rem;
  left: -15rem;
  top: 32vh;
  background: rgba(141, 38, 55, 0.04);
}

.ambient-two {
  width: 21rem;
  height: 21rem;
  right: -11rem;
  bottom: 5vh;
  background: rgba(86, 114, 103, 0.06);
}

.topbar {
  width: min(1680px, calc(100% - 64px));
  min-height: 84px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: block;
  flex: 0 0 auto;
  object-fit: cover;
  object-position: center;
  border: 1px solid rgba(141, 38, 55, .16);
  border-radius: 14px;
}

.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: 0.08em; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 11px; letter-spacing: 0.12em; }

.shell {
  width: min(1600px, calc(100% - 64px));
  margin: 28px auto 120px;
}

#appView {
  position: relative;
  isolation: isolate;
}

#appView::before {
  content: "";
  position: absolute;
  z-index: -2;
  inset: -18px;
  border-radius: 38px;
  opacity: 0;
  background-position: center;
  background-size: cover;
  filter: saturate(.84) blur(1px);
  pointer-events: none;
  transition: opacity 180ms ease;
}

#appView::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -18px;
  border-radius: 38px;
  opacity: 0;
  background: rgba(245, 241, 235, .68);
  pointer-events: none;
  transition: opacity 180ms ease;
}

#appView.has-chat-background::before {
  opacity: .34;
  background-image: var(--chat-background-image);
}

#appView.has-chat-background::after { opacity: 1; }
#appView > * { position: relative; z-index: 1; }

.surface {
  border: 1px solid rgba(255, 255, 255, 0.8);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.auth-layout {
  min-height: calc(100vh - 190px);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 72px;
  align-items: center;
}

.auth-layout,
.auth-copy,
.auth-card,
.auth-card form,
.auth-card label {
  min-width: 0;
}

.auth-copy h1 {
  margin: 8px 0 22px;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: clamp(42px, 6vw, 72px);
  font-weight: 500;
  line-height: 1.18;
  letter-spacing: 0.02em;
}

.auth-copy > p:last-child { max-width: 29rem; color: var(--muted); font-size: 17px; }

.auth-card {
  width: 100%;
  padding: 36px;
  border-radius: var(--radius);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1, h2, h3, p { overflow-wrap: anywhere; }
h1, h2, h3 { margin-top: 0; }
h2 { margin-bottom: 8px; font-family: "Songti SC", "STSong", serif; font-size: 28px; font-weight: 500; }
h3 { margin-bottom: 6px; }
.muted { color: var(--muted); }
.fineprint { color: var(--muted); font-size: 12px; }

label {
  display: grid;
  gap: 8px;
  margin: 20px 0;
  color: #56524d;
  font-size: 13px;
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line);
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.8);
  border-radius: 15px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea { padding-block: 13px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: rgba(141, 38, 55, 0.55);
  box-shadow: 0 0 0 4px rgba(141, 38, 55, 0.08);
}

.primary, .secondary, .ghost {
  min-height: 46px;
  padding: 0 20px;
  border-radius: 15px;
  border: 1px solid transparent;
  font-weight: 600;
  transition: transform 150ms ease, background 150ms ease;
}

.primary { color: white; background: var(--accent); }
.primary:hover { background: var(--accent-deep); transform: translateY(-1px); }
.secondary { color: var(--accent); border-color: rgba(141, 38, 55, 0.18); background: rgba(255,255,255,.56); }
.ghost { color: #56524d; border-color: var(--line); background: transparent; }
.compact { min-height: 38px; padding: 0 14px; }
.wide { width: 100%; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  top: 22px;
  width: min(440px, calc(100% - 32px));
  padding: 13px 18px;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(36, 33, 31, 0.94);
  border-radius: 14px;
  box-shadow: 0 15px 45px rgba(0,0,0,.18);
  text-align: center;
}

.toast.error { background: rgba(125, 27, 43, 0.96); }

.center-state {
  min-height: 60vh;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}

.center-state p { color: var(--muted); }
.loader {
  width: 38px;
  height: 38px;
  margin-bottom: 22px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.welcome-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin: 12px 0 26px;
}

.welcome-row h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", serif;
  font-size: clamp(32px, 5vw, 46px);
  font-weight: 500;
}

.device-switcher {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}

.device-switcher::-webkit-scrollbar { display: none; }

.device-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  color: #625f5a;
  background: rgba(255,255,255,.45);
  border-radius: 999px;
}

.device-chip.active { color: #fff; border-color: var(--accent); background: var(--accent); }
.device-chip-dot { width: 7px; height: 7px; background: #a8aaa7; border-radius: 50%; }
.device-chip-dot.online { background: #62b383; }

.panel { display: none; }
.panel.active { display: block; animation: reveal 230ms ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }

.character-hero {
  min-height: 360px;
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) 1.2fr;
  align-items: center;
  overflow: hidden;
  border-radius: 34px;
}

.character-art-wrap { position: relative; align-self: stretch; min-height: 360px; background: linear-gradient(145deg, #d9c0bc, #baa5a4); }
.character-art { width: 100%; height: 100%; object-fit: cover; display: block; }
.online-dot { position: absolute; right: 18px; top: 18px; width: 13px; height: 13px; border: 3px solid #fff; background: #5db17d; border-radius: 50%; }
.online-dot.offline { background: #9e9e9b; }

.character-copy { padding: clamp(28px, 6vw, 62px); }
.character-copy h2 { margin: 0 0 14px; font-size: clamp(40px, 6vw, 62px); }
.role-tagline { max-width: 31rem; min-height: 3.1em; color: var(--muted); font-size: 16px; }
.hero-actions { display: flex; gap: 10px; margin-top: 28px; }

.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.quick-card {
  min-height: 96px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid rgba(255,255,255,.8);
  color: var(--ink);
  background: rgba(255,255,255,.58);
  border-radius: 22px;
  text-align: left;
}
.quick-card span:last-child, .quick-card strong, .quick-card small { display: block; }
.quick-card small { margin-top: 3px; color: var(--muted); }
.quick-icon { width: 44px; height: 44px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); border-radius: 14px; font-family: serif; font-size: 20px; }

.panel-heading { margin: 34px 0 22px; }
.panel-heading > p { max-width: 38rem; color: var(--muted); }
.role-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.role-card { overflow: hidden; border-radius: 28px; background: var(--surface-solid); box-shadow: var(--shadow); }
.role-cover { position: relative; height: 330px; overflow: hidden; background: #d2c7c0; }
.role-cover img { width: 100%; height: 100%; object-fit: cover; transition: transform 500ms ease; }
.role-card:hover .role-cover img { transform: scale(1.025); }
.role-badge { position: absolute; left: 16px; top: 16px; padding: 6px 10px; color: #fff; background: rgba(30,28,27,.68); border-radius: 999px; font-size: 11px; backdrop-filter: blur(8px); }
.role-body { padding: 22px; }
.role-body h3 { font-family: "Songti SC", serif; font-size: 27px; font-weight: 500; }
.role-tags { display: flex; flex-wrap: wrap; gap: 7px; margin: 16px 0; }
.role-tags span { padding: 5px 9px; color: #716863; background: #f2ece7; border-radius: 999px; font-size: 11px; }
.role-actions { display: flex; gap: 10px; }
.role-actions button { flex: 1; }

.setting-list, .privacy-note, .memory-card, .steps, .help-note { border-radius: 26px; }
.setting-list { overflow: hidden; }
.setting-row, .setting-action {
  width: 100%;
  min-height: 64px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
  text-align: left;
}
.setting-row span { color: var(--muted); }
.setting-row strong { max-width: 62%; text-align: right; font-size: 13px; overflow-wrap: anywhere; }
.setting-action:last-child { border-bottom: 0; }
.setting-action span { color: var(--muted); font-size: 24px; }
.setting-action.caution { color: #8b5a20; }
.setting-action.danger-text { color: #9a2538; }
.setting-action:disabled { cursor: not-allowed; opacity: .42; }

/* 设备设置内容独立滚动，避免移动端被固定底栏挡住。 */
#devicePanel.active {
  max-height: calc(100dvh - 84px - 68px - 32px);
  padding-bottom: 96px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* 记忆总览和明细页也独立滚动，避免内容把整页越堆越长。 */
#memoryPanel.active {
  max-height: calc(100dvh - 84px - 68px - 32px);
  padding-bottom: 96px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* The Memory Universe is full-screen in production. Keep the review entry
   additive and above the renderer without changing the constellation contract. */
.memory-candidate-review-dock { display: none; }
body[data-view^="memory-universe"] #memoryPanel > #memoryCandidateReviewDock {
  position: fixed;
  z-index: 52;
  top: 74px;
  right: 22px;
  display: block !important;
  width: min(430px, calc(100vw - 32px));
  color: #f2f3ff;
}
.memory-candidate-review-toggle {
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(228, 216, 255, .28);
  color: #f8f3ff;
  background: rgba(24, 20, 48, .74);
  border-radius: 999px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
  backdrop-filter: blur(14px);
  cursor: pointer;
}
.memory-candidate-review-toggle strong {
  min-width: 22px;
  padding: 2px 7px;
  color: #251c2b;
  background: #f4c6b2;
  border-radius: 999px;
  font-size: 12px;
}
.memory-candidate-review-card {
  margin-top: 10px;
  padding: 18px;
  color: #282131;
  background: rgba(252, 249, 255, .97);
  border: 1px solid rgba(233, 220, 255, .8);
  border-radius: 20px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .34);
}
.memory-candidate-review-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.memory-candidate-review-heading h3 { margin: 3px 0 0; font-size: 18px; }
.memory-candidate-review-hint, .memory-candidate-review-empty { margin: 10px 0 0; color: #756b81; font-size: 12px; line-height: 1.55; }
.memory-candidate-review-list { display: grid; gap: 10px; max-height: min(58dvh, 520px); margin-top: 14px; overflow-y: auto; }
.memory-candidate-review-item { padding: 13px; background: #f5f0fa; border: 1px solid #ebe2f3; border-radius: 14px; }
.memory-candidate-review-item-content { margin: 0; color: #33283b; white-space: pre-wrap; font-size: 13px; line-height: 1.6; }
.memory-candidate-review-item-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; color: #81758b; font-size: 11px; }
.memory-candidate-review-item-actions { display: flex; gap: 8px; margin-top: 11px; }
.memory-candidate-review-item-actions button { flex: 1; min-height: 34px; border-radius: 10px; }
.memory-candidate-review-item-actions .confirm { color: #fff; background: #7653a6; }
.memory-candidate-review-item-actions .reject { color: #76536a; background: rgba(255, 255, 255, .8); border: 1px solid #dfd2e7; }
.memory-candidate-review-item-actions button:disabled { cursor: wait; opacity: .55; }
@media (max-width: 760px) {
  body[data-view^="memory-universe"] #memoryPanel > #memoryCandidateReviewDock { top: 62px; right: 12px; width: calc(100vw - 24px); }
}

.memory-card { min-height: 180px; padding: 30px; display: flex; align-items: center; gap: 24px; }
.memory-orbit { flex: 0 0 auto; width: 82px; height: 82px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); border-radius: 50%; font-family: serif; font-size: 36px; }
.memory-status-card { min-height: 150px; }
.memory-status-copy { flex: 1; min-width: 0; }
.memory-status-line { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.memory-status-actions { display: flex; align-items: center; gap: 12px; }
.memory-role-select {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.memory-role-select select { min-height: 34px; padding: 0 28px 0 10px; font-size: 12px; }
.memory-status-card p { margin: 5px 0 0; color: var(--muted); }
.memory-status-card .eyebrow { margin: 0; color: var(--accent); }
.toggle { display: inline-flex; margin: 0; cursor: pointer; }
.toggle input { position: absolute; width: 1px; height: 1px; min-height: 0; opacity: 0; pointer-events: none; }
.toggle-track {
  position: relative;
  width: 50px;
  height: 29px;
  background: #cbc5bf;
  border-radius: 999px;
  transition: background 160ms ease;
}
.toggle-track::after {
  content: "";
  position: absolute;
  width: 23px;
  height: 23px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(32, 32, 31, .18);
  transition: transform 160ms ease;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(21px); }
.toggle input:focus-visible + .toggle-track { box-shadow: 0 0 0 4px rgba(141, 38, 55, .12); }
.memory-overview-card { margin-top: 16px; padding: 26px; border-radius: 26px; }
.memory-overview-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.memory-overview-heading h3 { margin: 0; }
.memory-count-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 22px; }
.memory-count-card { min-height: 88px; padding: 16px; border: 0; color: inherit; background: rgba(245, 241, 235, .74); border-radius: 16px; text-align: left; transition: transform .16s ease, background .16s ease; }
.memory-count-card:hover, .memory-count-card:focus-visible { background: #f0e4e2; transform: translateY(-1px); }
.memory-count-grid strong, .memory-count-grid span { display: block; }
.memory-count-grid strong { color: var(--accent); font-size: 24px; line-height: 1.1; }
.memory-count-grid span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.memory-overview-hint { margin: 18px 0 0; color: var(--muted); font-size: 13px; }
.relationship-progress-card { margin-top: 16px; padding: 24px 26px; border-radius: 26px; }
.relationship-progress-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.relationship-progress-heading h3 { margin: 2px 0 0; }
.relationship-stage-rank { min-width: 46px; padding: 6px 8px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 12px; font-weight: 700; text-align: center; }
.relationship-progress-copy { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.relationship-progress-bar { height: 7px; margin: 16px 0; overflow: hidden; border-radius: 999px; background: #eee7e2; }
.relationship-progress-bar span { display: block; width: 4%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #9f3043, #dc8b78); transition: width .28s ease; }
.relationship-milestone-list { display: grid; gap: 8px; }
.relationship-milestone, .relationship-milestone-empty { margin: 0; color: #5f5551; font-size: 13px; line-height: 1.55; }
.relationship-milestone::before { content: "·"; margin-right: 7px; color: var(--accent); font-weight: 800; }
.relationship-milestone-empty { color: var(--muted); }
.memory-detail-card { margin-top: 16px; padding: 28px; border-radius: 26px; }
.memory-detail-heading { display: flex; align-items: start; justify-content: space-between; gap: 18px; }
.memory-count { color: var(--muted); font-size: 12px; }
.memory-add-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; margin-top: 18px; }
.memory-add-row input { min-height: 46px; }
.memory-empty { margin: 18px 0 0; color: var(--muted); font-size: 13px; }
.memory-list { display: grid; gap: 10px; margin-top: 16px; }
.memory-list:empty { display: none; }
.memory-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 15px;
  background: rgba(245, 241, 235, .74);
  border-radius: 16px;
}
.memory-item-copy { min-width: 0; }
.memory-item-copy p { margin: 0; white-space: pre-wrap; font-size: 13px; line-height: 1.65; }
.memory-item-copy small { display: block; margin-top: 4px; color: var(--muted); }
.memory-item-actions { display: flex; gap: 5px; }
.memory-item-actions button {
  min-height: 34px;
  padding: 0 9px;
  border: 0;
  color: var(--muted);
  background: rgba(255, 255, 255, .68);
  border-radius: 10px;
}
.memory-item-actions button:hover { color: var(--accent); }
.memory-summary {
  min-height: 96px;
  max-height: 360px;
  margin-top: 18px;
  padding: 18px;
  overflow: auto;
  white-space: pre-wrap;
  background: rgba(245, 241, 235, .74);
  border-radius: 18px;
  font-size: 13px;
  line-height: 1.75;
}
.memory-clear { width: 100%; margin-top: 14px; }
.memory-collection-dialog { width: min(680px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); }
.memory-collection-card { width: auto; max-height: calc(100dvh - 28px); overflow-y: auto; box-sizing: border-box; }
.memory-collection-actions { justify-content: flex-end; }
.memory-collection-recent .memory-list { max-height: min(50dvh, 620px); padding-right: 4px; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.privacy-note, .help-note { margin-top: 16px; padding: 26px; }
.privacy-note p, .help-note p { color: var(--muted); }

.steps { padding: 10px 26px; list-style: none; counter-reset: none; }
.steps li { padding: 22px 0; display: flex; gap: 18px; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps li > span { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; color: #fff; background: var(--accent); border-radius: 50%; }
.steps p { margin: 4px 0 0; color: var(--muted); }

/* 历史面板：独立滚动，不带动顶栏和底栏 */
#historyPanel.active {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 84px - 68px - 32px);
}
#historyPanel .panel-heading,
#historyPanel .history-privacy {
  flex: 0 0 auto;
}
#historyPanel .history-layout {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.history-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.history-heading-actions { display: flex; gap: 8px; align-items: center; }
.history-role-select {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.history-role-select select { min-height: 34px; padding: 0 28px 0 10px; font-size: 12px; }
.danger-outline { color: var(--accent); border-color: rgba(141, 38, 55, .24); }
.danger-outline:hover { color: #fff; background: var(--accent); border-color: var(--accent); }
.history-privacy { margin: -10px 0 18px; color: var(--muted); font-size: 13px; }
.history-layout {
  min-height: 580px;
  display: grid;
  grid-template-columns: minmax(220px, 32%) minmax(0, 1fr);
  overflow: hidden;
  border-radius: 26px;
}
.history-sidebar {
  padding: 14px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(248, 244, 239, .68);
}
.history-session-list { display: grid; gap: 7px; }
.history-session {
  width: 100%;
  padding: 15px;
  display: grid;
  gap: 5px;
  border: 0;
  color: var(--ink);
  background: transparent;
  border-radius: 15px;
  text-align: left;
}
.history-session:hover { background: rgba(255, 255, 255, .7); }
.history-session.active { background: var(--surface-solid); box-shadow: 0 7px 24px rgba(50, 42, 39, .08); }
.history-session strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.history-session span { color: var(--muted); font-size: 11px; }
.history-detail { min-width: 0; background: rgba(255, 255, 255, .44); }
.history-detail-empty {
  min-height: 580px;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}
.history-detail-empty span {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 20px;
  font-family: serif;
  font-size: 22px;
}
.history-detail-empty h3 { margin: 14px 0 4px; color: var(--ink); }
.history-detail-empty p { margin: 0; }
.history-conversation-heading {
  position: sticky;
  z-index: 2;
  top: 0;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, .92);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}
.history-conversation-heading h3 { margin: 0; }
.history-conversation-heading p { margin: 4px 0 0; }
.history-message-list {
  min-height: 500px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.history-message {
  width: fit-content;
  max-width: min(78%, 560px);
  padding: 13px 15px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 17px 17px 17px 5px;
  box-shadow: 0 7px 20px rgba(50, 42, 39, .05);
}
.history-message.from-user {
  align-self: flex-end;
  color: #fff;
  background: var(--accent);
  border-color: transparent;
  border-radius: 17px 17px 5px 17px;
}
.history-message p { margin: 0; white-space: pre-wrap; line-height: 1.65; }
.history-message small { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.history-message.from-user small { color: rgba(255, 255, 255, .72); }

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(650px, calc(100% - 24px));
  height: 68px;
  padding: 6px 10px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,.85);
  background: rgba(255,253,249,.88);
  border-radius: 24px;
  box-shadow: 0 14px 45px rgba(49,40,36,.16);
  backdrop-filter: blur(20px);
}
.bottom-nav button { border: 0; color: #8a8580; background: transparent; border-radius: 16px; font-size: 10px; }
.bottom-nav button span { display: block; font-size: 20px; line-height: 24px; }
.bottom-nav button.active { color: var(--accent); background: rgba(141,38,55,.07); }
.bottom-nav .nav-main { width: 50px; height: 50px; min-width: 50px; place-self: center; color: #fff; background: var(--accent); border-radius: 18px 18px 18px 7px; }
.bottom-nav .nav-main span { font-size: 24px; line-height: 1; }

dialog {
  width: min(460px, calc(100% - 28px));
  padding: 0;
  border: 0;
  background: transparent;
}
dialog::backdrop { background: rgba(27,24,23,.46); backdrop-filter: blur(7px); }
.dialog-card { position: relative; margin: 0; padding: 34px; border: 1px solid rgba(255,255,255,.8); background: #fffdf9; border-radius: 28px; box-shadow: 0 30px 90px rgba(20,17,16,.25); }
.dialog-close { position: absolute; z-index: 2; right: 12px; top: 10px; width: 44px; height: 44px; padding: 0; border: 0; color: var(--muted); background: transparent; border-radius: 50%; font-size: 26px; line-height: 1; cursor: pointer; touch-action: manipulation; }
.dialog-close:hover, .dialog-close:focus-visible { color: var(--ink); background: rgba(141,38,55,.08); }
.code-input { height: 64px; margin: 18px 0; text-align: center; font-size: 28px; font-weight: 600; letter-spacing: .26em; text-transform: uppercase; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.dialog-actions button { padding-inline: 10px; white-space: nowrap; }
.confirm-avatar-wrap { width: 92px; height: 92px; margin: -4px auto 20px; overflow: hidden; background: #ddd; border-radius: 50%; }
.confirm-avatar-wrap img { width: 100%; height: 100%; object-fit: cover; }
.action-notice {
  margin-top: 18px;
  padding: 15px 17px;
  color: #5f5149;
  background: #f6eee8;
  border-radius: 16px;
  font-size: 13px;
}
.action-notice strong { display: block; margin-bottom: 3px; color: var(--ink); }
.bind-success-dialog { width: min(460px, calc(100vw - 28px)); }
.bind-success-card { text-align: center; }
.bind-success-card .eyebrow { margin-top: 6px; }
.bind-success-card h2 { margin-bottom: 10px; }
.bind-success-card .muted { margin: 0; }
.bind-success-notice { margin: 24px 0; text-align: left; line-height: 1.65; }
.primary.danger { background: #9a2538; }
.primary.danger:hover { background: #741829; }
.diy-settings-dialog { width: min(620px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); }
.diy-settings-card { width: auto; max-height: calc(100dvh - 28px); overflow-y: auto; box-sizing: border-box; }
.diy-settings-card label { display: grid; gap: 8px; margin-top: 16px; color: var(--ink); font-size: 14px; font-weight: 650; }
.diy-settings-card input, .diy-settings-card textarea { width: 100%; min-width: 0; box-sizing: border-box; }
.diy-image-section { margin-top: 18px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: #fcfaf8; }
.diy-image-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; color: var(--ink); font-size: 14px; font-weight: 650; }
.diy-image-heading small { color: var(--muted); font-size: 11px; font-weight: 400; }
.diy-image-row { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.diy-image-preview-wrap { width: 112px; height: 84px; flex: 0 0 auto; display: grid; place-items: center; overflow: hidden; border: 1px dashed #cfc7c0; border-radius: 12px; background: #f1ece7; color: #ad908e; }
.diy-image-preview-wrap img { width: 100%; height: 100%; object-fit: cover; }
.diy-image-preview-wrap span { font-size: 24px; }
.diy-image-controls { min-width: 0; flex: 1; }
.diy-image-controls input { margin: 0; padding: 7px; font-size: 12px; }
.diy-image-controls p { margin: 7px 0 10px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.diy-image-controls > div { display: flex; align-items: center; gap: 12px; }
.diy-image-controls .ghost { min-height: 34px; padding: 6px 12px; font-size: 12px; }
.diy-image-controls .text-button { padding: 5px 0; color: #9f4e54; font-size: 12px; }
@media (max-width: 460px) { .diy-image-row { align-items: flex-start; } .diy-image-preview-wrap { width: 96px; height: 72px; } }
.diy-prompt-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; color: var(--ink); font-size: 14px; font-weight: 650; }
.diy-custom-toggle { display: inline-flex !important; grid-template-columns: none !important; align-items: center; gap: 9px !important; margin: 0 !important; color: var(--muted) !important; font-weight: 500 !important; cursor: pointer; }
.diy-custom-toggle input { position: absolute; width: 1px !important; height: 1px; opacity: 0; pointer-events: none; }
.diy-custom-toggle i { position: relative; width: 42px; height: 24px; display: block; background: #d8d4d0; border-radius: 999px; transition: background .18s ease; }
.diy-custom-toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.18); transition: transform .18s ease; }
.diy-custom-toggle input:checked + i { background: #5399ef; }
.diy-custom-toggle input:checked + i::after { transform: translateX(18px); }
.diy-custom-toggle input:focus-visible + i { outline: 3px solid rgba(83,153,239,.3); outline-offset: 2px; }
.diy-prompt-box { position: relative; margin-top: 10px; }
.diy-settings-card #diyCustomPromptInput { margin: 0; min-height: 206px; padding-bottom: 30px; resize: vertical; line-height: 1.62; }
.diy-settings-card #diyCustomPromptInput:disabled { color: #716b67; background: #f5f0eb; cursor: not-allowed; }
.diy-prompt-hint { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.diy-prompt-count { position: absolute; right: 12px; bottom: 9px; margin: 0; color: var(--muted); font-size: 12px; pointer-events: none; }
.diy-voice-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 10px; color: var(--ink); font-weight: 650; }
.diy-voice-heading small { color: var(--muted); font-weight: 400; }
.diy-voice-list { position: relative; }
.diy-voice-combobox { position: relative; }
.diy-voice-combobox-trigger { width: 100%; min-height: 62px; padding: 10px 14px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; border: 1px solid var(--line); color: var(--ink); background: #fff; border-radius: 14px; text-align: left; font: inherit; cursor: pointer; }
.diy-voice-combobox-trigger span { font-weight: 650; }
.diy-voice-combobox-trigger small { color: var(--muted); font-size: 11px; }
.diy-voice-combobox-trigger b { grid-row: 1 / span 2; grid-column: 2; color: var(--muted); font-size: 17px; font-weight: 400; }
.diy-voice-combobox-panel { position: absolute; z-index: 12; top: calc(100% + 7px); left: 0; right: 0; padding: 10px; border: 1px solid var(--line); background: #fff; border-radius: 16px; box-shadow: 0 16px 36px rgba(54,32,28,.15); }
.diy-voice-combobox-panel input { width: 100%; min-height: 40px; margin: 0 0 8px; }
.diy-voice-combobox-options { max-height: 274px; overflow-y: auto; display: grid; gap: 7px; }
.diy-voice-combobox-empty { margin: 8px; color: var(--muted); font-size: 13px; text-align: center; }
.diy-voice-option { min-height: 54px; padding: 8px 9px 8px 13px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); color: var(--ink); background: #fff; border-radius: 14px; text-align: left; }
.diy-voice-option.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px rgba(141,38,55,.12); }
.diy-voice-select { flex: 1; min-width: 0; border: 0; color: inherit; background: transparent; text-align: left; font: inherit; cursor: pointer; }
.diy-voice-select small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 400; }
.diy-voice-option.selected .diy-voice-select small { color: #8f4d59; }
.diy-voice-preview { width: 34px; height: 34px; padding: 0; flex: 0 0 auto; border: 1px solid var(--line); color: var(--accent); background: rgba(255,255,255,.78); border-radius: 50%; font-size: 15px; }
.diy-voice-preview:hover, .diy-voice-preview:focus-visible { color: #fff; background: var(--accent); border-color: var(--accent); }
#roleVoiceSettingsDialog { width: min(660px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); }
.role-voice-settings-card { width: 100%; max-height: calc(100dvh - 28px); box-sizing: border-box; overflow-x: hidden; overflow-y: auto; }
.role-voice-list { max-height: min(48dvh, 420px); margin-top: 22px; overflow-y: auto; overscroll-behavior: contain; padding-right: 3px; }
.role-voice-list .diy-voice-option { min-height: 62px; }

@media (max-width: 760px) {
  .topbar, .shell { width: min(100% - 28px, 600px); }
  .topbar { min-height: 70px; }
  .shell { margin-top: 12px; }
  .auth-layout { min-height: auto; grid-template-columns: 1fr; gap: 28px; padding-top: 5vh; }
  .auth-copy h1 { font-size: 43px; }
  .auth-copy > p:last-child { font-size: 15px; }
  .auth-card { padding: 25px; }
  .welcome-row { align-items: center; }
  .welcome-row .secondary { padding: 0 13px; font-size: 12px; }
  .character-hero { grid-template-columns: 1fr; }
  .character-art-wrap { min-height: 310px; max-height: 44vh; }
  .character-copy { padding: 28px; }
  .character-copy h2 { font-size: 42px; }
  .quick-grid, .role-grid { grid-template-columns: 1fr; }
  .role-cover { height: min(98vw, 430px); }
  .memory-card { align-items: flex-start; }
  .memory-add-row { grid-template-columns: 1fr; }
  .memory-add-row button { width: 100%; }
  .memory-status-line { align-items: flex-start; flex-direction: column; gap: 10px; }
  .memory-status-actions { width: 100%; justify-content: space-between; }
  .memory-role-select { min-width: 0; }
  .memory-role-select select { min-width: 0; max-width: 180px; }
  .memory-overview-heading { align-items: flex-start; flex-direction: column; }
  .memory-overview-heading button { width: 100%; }
  .memory-count-grid { gap: 7px; }
  .memory-count-card { min-height: 92px; padding: 13px 10px; }
  .memory-count-grid strong { font-size: 21px; }
  .memory-collection-dialog { width: 100%; max-width: 100%; margin: auto 0 0; border: 0; border-radius: 22px 22px 0 0; }
  .memory-collection-card { max-height: min(78dvh, 680px); padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; }
  .memory-collection-actions { position: sticky; bottom: -24px; padding: 14px 0 calc(4px + env(safe-area-inset-bottom)); background: var(--surface-solid); }
  .memory-collection-actions button { flex: 1; min-height: 46px; }
  .memory-collection-recent .memory-list { max-height: 48dvh; }
  .history-layout { min-height: 0; grid-template-columns: 1fr; }
  .history-sidebar { max-height: 280px; border-right: 0; border-bottom: 1px solid var(--line); }
  .history-detail-empty { min-height: 300px; }
  .history-message-list { min-height: 380px; padding: 16px; }
  .history-message { max-width: 88%; }
  .history-heading { align-items: start; }
  .history-heading-actions { flex-wrap: wrap; justify-content: flex-end; }
  .history-role-select select { max-width: 160px; }
  .history-conversation-heading { padding: 16px; }
  .diy-voice-list { grid-template-columns: 1fr; }
  #roleVoiceSettingsDialog { width: min(100%, calc(100vw - 16px)); margin: auto 8px; }
  .role-voice-settings-card { padding: 26px 20px calc(22px + env(safe-area-inset-bottom)); border-radius: 22px; }
  .role-voice-list { max-height: min(48dvh, 520px); }
}

@media (max-width: 410px) {
  .topbar, .shell { width: calc(100% - 22px); }
  .brand small { display: none; }
  .auth-copy h1 { font-size: 38px; }
  .character-art-wrap { min-height: 270px; }
  .hero-actions { flex-direction: column; }
  .hero-actions button { width: 100%; }
  .memory-card { flex-direction: column; }
  .bottom-nav { width: calc(100% - 16px); }
}

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

/* Customer service centre and single-page mobile scrolling. */
.voice-service-hero{padding:24px;border-radius:26px;background:linear-gradient(135deg,rgba(141,38,55,.12),rgba(255,255,255,.84) 58%)}.voice-service-topline{display:flex;align-items:center;justify-content:space-between;gap:12px;color:var(--muted);font-size:12px}.voice-status-chip{min-height:28px;padding:5px 10px;color:#496055;background:rgba(111,140,122,.15);border-radius:999px;font-weight:700}.voice-service-hero[data-status="warning"] .voice-status-chip{color:#8b5a20;background:#f6ead9}.voice-service-hero[data-status="text_only"] .voice-status-chip{color:var(--accent);background:var(--accent-soft)}.voice-service-hero>strong{display:block;margin-top:22px;font-family:"Songti SC","STSong",serif;font-size:clamp(26px,4vw,38px);font-weight:500;line-height:1.2}.voice-service-hero>p{margin:8px 0 0;color:var(--muted)}.voice-service-bar,.voice-quota-progress{height:9px;overflow:hidden;background:rgba(93,74,65,.12);border-radius:999px}.voice-service-bar{margin-top:22px}.voice-service-bar>span,.voice-quota-progress>span{display:block;height:100%;border-radius:inherit;background:var(--sage)}.voice-service-hero[data-status="warning"] .voice-service-bar>span,.voice-quota-device[data-status="warning"] .voice-quota-progress>span{background:#be7b25}.voice-service-hero[data-status="text_only"] .voice-service-bar>span,.voice-quota-device[data-status="text_only"] .voice-quota-progress>span{background:var(--accent)}.voice-quota-device-list{display:grid;gap:12px;margin-top:16px}.voice-quota-device{padding:18px 20px;display:grid;grid-template-columns:minmax(160px,.7fr) minmax(240px,1.3fr);gap:24px;align-items:center;border-radius:20px}.voice-quota-device-copy strong,.voice-quota-device-copy small{display:block}.voice-quota-device-copy small,.voice-quota-progress-wrap small{margin-top:4px;color:var(--muted);font-size:12px}.voice-quota-progress-wrap small{display:block}.voice-service-note{margin-top:16px;padding:20px 22px;border-radius:20px}.voice-service-note strong{color:var(--accent)}.voice-service-note p{margin:5px 0 0;color:var(--muted);font-size:13px}#devicePanel.active,#memoryPanel.active{max-height:none;padding-bottom:0;overflow:visible;overscroll-behavior:auto}#historyPanel.active{display:block;max-height:none}#historyPanel .history-layout,.history-sidebar{overflow:visible}@media(max-width:760px){.quick-grid{grid-template-columns:1fr 1fr;gap:10px}.quick-card{min-height:118px;padding:18px 15px;align-items:flex-start}.quick-card small{line-height:1.45}.voice-service-topline{align-items:flex-start;flex-direction:column;gap:8px}.voice-quota-device{grid-template-columns:1fr;gap:14px}.history-sidebar{max-height:none}}

/* Keep fixed navigation below content instead of covering the final card. */
#appView { padding-bottom: 112px; }
.bottom-nav { bottom: max(0px, env(safe-area-inset-bottom)); }
.voice-quota-device-list:empty { display: none; }

/* Stable desktop navigation and bounded history list. The bar sits on the
   screen edge, so it grows by the home-indicator inset and keeps its buttons
   above it (the full-screen star map floats the bar instead, below). */
.bottom-nav { position: fixed !important; bottom: 0 !important; height: calc(68px + env(safe-area-inset-bottom)); padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
body[data-view^="memory-universe"] .bottom-nav { height: 68px; padding-bottom: 6px; }
@media (min-width: 761px) { #historyPanel .history-layout { max-height: min(66dvh, 720px); overflow: hidden; } #historyPanel .history-sidebar { overflow-y: auto; overscroll-behavior: contain; } #historyPanel .history-detail { overflow-y: auto; } }
@media (max-width: 760px) { .history-session-list { max-height: 300px; overflow-y: auto; overscroll-behavior: contain; } }
.memory-select-check { width:20px; min-width:20px; height:20px; min-height:20px; margin:0 12px 0 0; accent-color:var(--accent); }
.memory-item.selected { background:#f8eded; outline:2px solid rgba(141,38,55,.24); }

/* Memory universe: visuals are generated only from user-visible, role-scoped memory rows. */
.memory-universe-card { overflow: hidden; }
.memory-view-tabs { display: inline-flex; gap: 4px; margin-top: 22px; padding: 4px; border-radius: 14px; background: #f3eeea; }
.memory-view-tab { min-height: 34px; padding: 0 14px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-size: 13px; font-weight: 700; }
.memory-view-tab.active { color: #fff; background: var(--accent); box-shadow: 0 4px 12px rgba(128, 30, 48, .18); }
.memory-view-caption { min-height: 22px; margin: 14px 0 8px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.memory-star-map { position: relative; min-height: 360px; overflow: hidden; border-radius: 20px; background: radial-gradient(circle at 55% 38%, rgba(132, 76, 99, .55), transparent 23%), radial-gradient(circle at 16% 86%, rgba(170, 97, 111, .34), transparent 32%), linear-gradient(145deg, #181725, #342331 56%, #1a1b2d); box-shadow: inset 0 0 72px rgba(7, 9, 20, .45); }
.memory-constellation-edges { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; pointer-events: none; }
.memory-thread-label { position: absolute; z-index: 0; max-width: 30%; overflow: hidden; color: rgba(255, 239, 232, .62); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.memory-thread-label-0 { left: 8%; top: 5%; }
.memory-thread-label-1 { right: 8%; top: 5%; }
.memory-thread-label-2 { left: 8%; bottom: 5%; }
.memory-thread-label-3 { right: 8%; bottom: 5%; }
.memory-star-map::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .45; background-image: radial-gradient(#fff 1px, transparent 1.5px), radial-gradient(#f6dfe2 .8px, transparent 1.4px); background-position: 0 0, 16px 24px; background-size: 34px 34px, 49px 49px; }
.memory-star { position: absolute; left: var(--star-x); top: var(--star-y); z-index: 1; width: var(--star-size); height: var(--star-size); padding: 0; border: 0; border-radius: 50%; background: #fce4a6; box-shadow: 0 0 0 4px rgba(255, 238, 180, .09), 0 0 16px 5px rgba(255, 221, 140, .5); transform: translate(-50%, -50%); transition: transform .18s ease, box-shadow .18s ease; }
.memory-star:hover, .memory-star:focus-visible { z-index: 2; outline: 0; transform: translate(-50%, -50%) scale(1.35); box-shadow: 0 0 0 6px rgba(255, 238, 180, .15), 0 0 24px 8px rgba(255, 221, 140, .72); }
.memory-star span { position: absolute; left: 50%; bottom: calc(100% + 9px); width: max-content; max-width: 155px; padding: 6px 8px; border-radius: 8px; color: #fff7f2; background: rgba(21, 17, 28, .88); font-size: 11px; line-height: 1.35; opacity: 0; pointer-events: none; transform: translate(-50%, 4px); transition: opacity .18s ease, transform .18s ease; }
.memory-star:hover span, .memory-star:focus-visible span { opacity: 1; transform: translate(-50%, 0); }
.memory-star.pinned { background: #ffdad8; box-shadow: 0 0 0 4px rgba(255, 213, 210, .1), 0 0 16px 5px rgba(255, 171, 166, .5); }
.memory-star.moment { background: #bde9ff; box-shadow: 0 0 0 4px rgba(189, 233, 255, .1), 0 0 16px 5px rgba(125, 198, 240, .48); }
.memory-star.promise { background: #e5c9ff; box-shadow: 0 0 0 4px rgba(229, 201, 255, .1), 0 0 16px 5px rgba(190, 135, 235, .48); }
.memory-star.fact { background: #d5f0cf; box-shadow: 0 0 0 4px rgba(213, 240, 207, .1), 0 0 16px 5px rgba(171, 220, 164, .45); }
.memory-star.synthetic { border: 2px solid rgba(255, 255, 255, .72); }
.memory-timeline-list { display: grid; gap: 9px; max-height: 470px; padding-right: 3px; overflow-y: auto; }
.memory-timeline-item { display: grid; grid-template-columns: 78px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; padding: 13px 14px; border: 1px solid rgba(143, 96, 101, .12); border-radius: 15px; color: inherit; background: #fcfaf8; text-align: left; }
.memory-timeline-item:hover, .memory-timeline-item:focus-visible { border-color: rgba(143, 48, 67, .35); background: #fff7f5; outline: 0; }
.memory-visual-label { color: var(--accent); font-size: 11px; font-weight: 800; }
.memory-timeline-item strong { overflow: hidden; font-size: 13px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.memory-timeline-item small { color: var(--muted); font-size: 11px; white-space: nowrap; }
.memory-universe-empty { display: grid; min-height: 180px; margin: 0; place-items: center; color: rgba(255,255,255,.78); font-size: 14px; text-align: center; }
.memory-timeline-list .memory-universe-empty { min-height: 120px; color: var(--muted); }
.relationship-journey-card { position: relative; }
.relationship-progress-copy { max-width: 680px; }
.relationship-suggestion { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; padding: 12px; border-radius: 14px; color: #75434c; background: #fbf0ef; font-size: 13px; line-height: 1.5; }
.relationship-stage-control { display: flex; align-items: end; gap: 10px; margin-top: 16px; }
.relationship-stage-control label { display: grid; flex: 1; gap: 6px; color: var(--muted); font-size: 12px; }
.relationship-stage-control select { min-height: 40px; }
.relationship-add-moment { margin-top: 16px; }
.relationship-milestone { width: 100%; padding: 0; border: 0; color: #5f5551; background: transparent; text-align: left; }
.relationship-milestone:hover, .relationship-milestone:focus-visible { color: var(--accent); outline: 0; }
.memory-detail-dialog { width: min(560px, calc(100vw - 28px)); }
.memory-detail-dialog-card { width: auto; }
.memory-detail-content { margin: 18px 0 8px; white-space: pre-wrap; color: var(--text); font-size: 15px; line-height: 1.75; }
.memory-detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.memory-detail-tags span { padding: 4px 8px; border-radius: 999px; color: #7b4a53; background: #f6e9e7; font-size: 12px; }
.memory-universe-v3-host { position: relative; width: 100%; min-height: min(78dvh, 860px); margin: -18px 0 20px; overflow: hidden; border-radius: 24px; background: #03040a; }
.memory-universe-v3-host .mu3-stage { position: relative; width: 100%; min-height: min(78dvh, 860px); height: min(78dvh, 860px); overflow: hidden; border-radius: inherit; background: #03040a; color: #eef2ff; font-family: Inter,system-ui,"PingFang SC",sans-serif; }
.memory-universe-v3-host .mu3-galaxy,.memory-universe-v3-host .mu3-overlay { position:absolute; inset:0; width:100%; height:100%; display:block; }
.memory-universe-v3-host .mu3-overlay { z-index:2; pointer-events:none; }
.memory-universe-v3-host .mu3-topbar { position:absolute; z-index:5; left:22px; top:18px; display:flex; align-items:baseline; gap:11px; padding:7px 11px; border:1px solid rgba(151,171,232,.22); border-radius:999px; background:rgba(7,10,24,.42); backdrop-filter:blur(16px); pointer-events:none; }
.memory-universe-v3-host .mu3-recent { position:absolute; z-index:6; left:22px; bottom:22px; display:grid; gap:5px; width:min(210px,calc(100% - 44px)); padding:10px; border:1px solid rgba(151,171,232,.16); border-radius:14px; background:rgba(7,10,24,.42); backdrop-filter:blur(16px); }
.memory-universe-v3-host .mu3-recent > span { color:rgba(218,225,250,.62); font-size:10px; letter-spacing:.08em; }
.memory-universe-v3-host .mu3-recent button { overflow:hidden; padding:0; border:0; color:rgba(242,236,255,.86); background:transparent; font:11px/1.45 system-ui; text-align:left; text-overflow:ellipsis; white-space:nowrap; cursor:pointer; }
.memory-universe-v3-host .mu3-recent button:hover { color:#ffe8bd; }
.memory-universe-v3-host .mu3-brand { color:#d8e1ff; font:9px ui-monospace,SFMono-Regular,Consolas,monospace; letter-spacing:.2em; }.memory-universe-v3-host .mu3-role { color:#ffe7b9; font-size:12px; }.memory-universe-v3-host .mu3-mode { color:#7f8eb8; font:9px ui-monospace,SFMono-Regular,Consolas,monospace; letter-spacing:.06em; }
.memory-universe-v3-host .mu3-hint { position:absolute; z-index:5; right:22px; top:22px; color:rgba(194,202,231,.45); font:10px system-ui; pointer-events:none; }
.memory-universe-v3-host .mu3-thread-strip { position:absolute; z-index:6; left:50%; bottom:18px; display:flex; gap:6px; transform:translateX(-50%); padding:5px 6px; border:1px solid rgba(143,161,221,.15); border-radius:999px; background:rgba(4,6,18,.38); backdrop-filter:blur(14px); white-space:nowrap; box-shadow:0 10px 38px rgba(0,0,0,.18); }
.memory-universe-v3-host .mu3-thread-strip button { appearance:none; border:0; padding:6px 10px; border-radius:999px; color:rgba(229,223,253,.68); font:10px system-ui; cursor:pointer; background:transparent; }.memory-universe-v3-host .mu3-thread-strip button:hover,.memory-universe-v3-host .mu3-thread-strip button[data-active=true] { color:#fff4d4; background:rgba(153,119,210,.22); }
.memory-universe-v3-host .mu3-detail { position:absolute; z-index:8; right:20px; top:20px; width:330px; max-height:calc(100% - 40px); padding:17px 18px 16px; border:1px solid rgba(192,180,255,.25); border-radius:18px; background:rgba(9,12,30,.62); backdrop-filter:blur(20px); box-shadow:0 20px 80px rgba(0,0,0,.36); color:#eef2ff; }.memory-universe-v3-host .mu3-detail-kicker { color:#b5a8eb; font:9px ui-monospace,SFMono-Regular,Consolas,monospace; letter-spacing:.15em; text-transform:uppercase; }.memory-universe-v3-host .mu3-detail-title { font-size:20px; font-weight:500; line-height:1.28; margin:8px 0 7px; }.memory-universe-v3-host .mu3-detail-meta { color:#aab2d3; font-size:11px; line-height:1.55; }.memory-universe-v3-host .mu3-detail-body { color:#e8eafb; font-size:13px; line-height:1.6; margin-top:12px; }.memory-universe-v3-host .mu3-detail-synthetic { display:inline-block; margin-top:9px; padding:5px 8px; border-radius:999px; color:#f6d9a4; background:rgba(174,126,57,.16); font-size:10px; }
.memory-universe-v3-host .mu3-hud { position:absolute; z-index:12; left:12px; top:52px; margin:0; padding:8px 10px; border:1px solid rgba(157,175,235,.28); border-radius:10px; color:#cbd5fa; background:rgba(2,5,16,.76); font:10px/1.45 ui-monospace,SFMono-Regular,Consolas,monospace; pointer-events:none; white-space:pre; }
 .memory-universe-v3-host .mu3-universe-state { position:absolute; z-index:7; inset:0; display:grid; place-content:center; justify-items:center; gap:12px; padding:24px; color:rgba(224,230,255,.76); text-align:center; pointer-events:none; }
 .memory-universe-v3-host .mu3-universe-copy { display:grid; justify-items:center; gap:7px; max-width:min(86vw,32em); text-shadow:0 2px 18px rgba(0,0,0,.55); }
 .memory-universe-v3-host .mu3-universe-main { color:rgba(239,235,255,.88); font-size:15px; line-height:1.45; }
 .memory-universe-v3-host .mu3-universe-secondary { color:rgba(213,218,244,.68); font-size:12px; line-height:1.5; }
 .memory-universe-v3-host .mu3-universe-subtitle { margin-top:5px; color:rgba(191,199,230,.52); font:10px/1.4 ui-monospace,SFMono-Regular,Consolas,monospace; letter-spacing:.08em; }
 .memory-universe-v3-host .mu3-universe-state button { pointer-events:auto; min-height:32px; padding:0 14px; border:1px solid rgba(184,195,241,.26); border-radius:999px; color:#f0eaff; background:rgba(111,94,174,.24); font:12px system-ui; cursor:pointer; }
 .memory-universe-route-error { display:grid; place-content:center; justify-items:center; gap:12px; width:100%; height:100%; color:rgba(224,230,255,.78); background:#03040a; text-align:center; }
 .memory-universe-route-error button { min-height:32px; padding:0 14px; border:1px solid rgba(184,195,241,.26); border-radius:999px; color:#f0eaff; background:rgba(111,94,174,.24); font:12px system-ui; cursor:pointer; }
@media(max-width:760px){.memory-universe-v3-host .mu3-stage{min-height:78dvh;height:78dvh;border-radius:20px}.memory-universe-v3-host .mu3-topbar{left:10px;top:10px;padding:7px 10px;gap:8px}.memory-universe-v3-host .mu3-mode{display:none}.memory-universe-v3-host .mu3-hint{right:12px;top:14px;font-size:9px}.memory-universe-v3-host .mu3-thread-strip{left:10px;right:10px;bottom:10px;transform:none;overflow-x:auto;justify-content:flex-start;gap:2px;padding:4px}.memory-universe-v3-host .mu3-thread-strip button{font-size:9px;padding:6px 8px;flex:0 0 auto;max-width:31vw;overflow:hidden;text-overflow:ellipsis}.memory-universe-v3-host .mu3-detail{left:10px;right:10px;top:auto;bottom:58px;width:auto;max-height:35dvh;padding:13px 14px;border-radius:17px}.memory-universe-v3-host .mu3-detail-title{font-size:18px;margin:6px 0 5px}.memory-universe-v3-host .mu3-detail-body{font-size:12px;margin-top:8px}}
.memory-universe-brand-host { position:relative; width:100%; min-height:min(78dvh,860px); margin:-18px 0 20px; overflow:hidden; border-radius:24px; background:#020410; }
.memory-universe-brand-host .fulan-memory-universe-root { position:relative; width:100%; min-height:min(78dvh,860px); height:min(78dvh,860px); overflow:hidden; border-radius:inherit; background:#020410; color:#e8eaf6; }
.memory-panel-brand #memoryUniverseBrandHost { display:block; }
.memory-panel-brand > .panel-heading, .memory-panel-brand > .memory-status-card, .memory-panel-brand > .memory-overview-card, .memory-panel-brand > .relationship-progress-card, .memory-panel-brand > .privacy-note { display:none; }
.memory-panel-brand > .relationship-progress-card { margin-top:16px; }
/* Canary Memory View is a full-bleed universe, while all other tabs retain the app shell. */
body:has(#memoryPanel.memory-panel-v3.active) { background:#03040a; overflow:hidden; }
body:has(#memoryPanel.memory-panel-v3.active) .topbar { position:fixed; z-index:35; left:0; right:0; top:0; width:100%; margin:0; padding:12px 22px; border:0; border-radius:0; background:linear-gradient(180deg,rgba(3,4,10,.78),rgba(3,4,10,0)); color:#eef2ff; box-shadow:none; }
body:has(#memoryPanel.memory-panel-v3.active) .topbar .brand small { color:rgba(208,216,242,.58); }
body:has(#memoryPanel.memory-panel-v3.active) .shell { width:100%; max-width:none; margin:0; padding:0; }
body:has(#memoryPanel.memory-panel-v3.active) #appView { min-height:100dvh; padding-bottom:0; background:#03040a; }
body:has(#memoryPanel.memory-panel-v3.active) #memoryPanel.active { height:100dvh; max-height:none; min-height:100dvh; padding:0; overflow:hidden; background:#03040a; }
body:has(#memoryPanel.memory-panel-v3.active) .memory-universe-v3-host { height:100dvh; min-height:100dvh; margin:0; border-radius:0; }
body:has(#memoryPanel.memory-panel-v3.active) .bottom-nav { z-index:40; color:#dce2fa; border-color:rgba(170,183,232,.22); background:rgba(6,9,22,.56); box-shadow:0 12px 42px rgba(0,0,0,.38); }
body:has(#memoryPanel.memory-panel-v3.active) .bottom-nav button { color:rgba(211,220,247,.62); }
body:has(#memoryPanel.memory-panel-v3.active) .bottom-nav button.active { color:#ffe8bd; background:rgba(158,135,222,.2); }
body:has(#memoryPanel.memory-panel-v3.active) .bottom-nav .nav-main { color:#fff; background:#7564ad; }
@media (max-width: 760px) {
  .memory-universe-v3-host { min-height: 78dvh; margin: -10px -2px 14px; border-radius: 20px; }
  body:has(#memoryPanel.memory-panel-v3.active) .topbar { padding:10px 12px; }
  body:has(#memoryPanel.memory-panel-v3.active) .memory-universe-v3-host { min-height:100dvh; margin:0; border-radius:0; }
}

/* V3.2 enters the Universe before any legacy memory content can paint. */
html:has(body[data-view^="memory-universe"]) { min-height:100%; background:#03040a; }
body[data-view^="memory-universe"] { min-height:100dvh; overflow:hidden; color:#eef2ff; background:#03040a; }
body[data-view^="memory-universe"] .ambient { display:none; }
body[data-view^="memory-universe"] .topbar { position:fixed; z-index:35; inset:0 0 auto; width:100%; min-height:0; margin:0; padding:calc(env(safe-area-inset-top) + 10px) 22px 10px; border:0; border-radius:0; color:#eef2ff; background:linear-gradient(180deg,rgba(3,4,10,.76),rgba(3,4,10,0)); box-shadow:none; }
body[data-view^="memory-universe"] .topbar .brand small { color:rgba(208,216,242,.58); }
body[data-view^="memory-universe"] .topbar .brand-mark { border-color:rgba(186,202,255,.22); }
body[data-view^="memory-universe"] .topbar .ghost { color:rgba(228,233,251,.72); border-color:rgba(187,199,239,.2); background:rgba(8,11,27,.2); }
body[data-view^="memory-universe"] .topbar-actions { display:none !important; }
body[data-view^="memory-universe"] .shell { width:100vw; max-width:none; min-height:100dvh; margin:0; padding:0; }
body[data-view^="memory-universe"] #appView { min-height:100dvh; padding:0; background:#03040a; }
body[data-view^="memory-universe"] #memoryPanel.active { position:fixed; inset:0; display:block; width:100vw; height:100dvh; min-height:100dvh; max-height:none; padding:0; overflow:hidden; background:#03040a; animation:none; }
body[data-view^="memory-universe"] #memoryPanel > :not(#memoryUniverseBrandHost) { display:none !important; }
body[data-view^="memory-universe"] .memory-universe-brand-host { display:block; width:100vw; height:100dvh; min-height:100dvh; margin:0; border-radius:0; background:#020410; }
body[data-view^="memory-universe"] .memory-universe-brand-host .fulan-memory-universe-root { width:100vw; height:100dvh; min-height:100dvh; border-radius:0; }
body[data-view^="memory-universe"] .memory-universe-route-loading { display:grid; width:100%; height:100%; place-items:center; color:rgba(222,229,255,.68); font-size:13px; letter-spacing:.08em; background:radial-gradient(circle at 50% 44%,rgba(57,43,94,.32),transparent 30%),#03040a; }
body[data-view^="memory-universe"] .bottom-nav { z-index:40; bottom:calc(env(safe-area-inset-bottom) + 10px) !important; color:#dce2fa; border-color:rgba(170,183,232,.22); background:rgba(6,9,22,.56); box-shadow:0 12px 42px rgba(0,0,0,.38); }
body[data-view^="memory-universe"] .bottom-nav button { color:rgba(211,220,247,.62); }
body[data-view^="memory-universe"] .bottom-nav button.active { color:#ffe8bd; background:rgba(158,135,222,.2); }
body[data-view^="memory-universe"] .bottom-nav .nav-main { color:#fff; background:#7564ad; }
body[data-view="memory-universe"] .mu3-topbar { top:calc(env(safe-area-inset-top) + 82px); }
body[data-view="memory-universe"] .mu3-thread-strip { bottom:96px; }
body[data-view="memory-universe"] .mu3-tools { position:fixed; z-index:44; top:calc(env(safe-area-inset-top) + 82px); right:22px; display:flex; gap:8px; }
body[data-view="memory-universe"] .mu3-tools button { min-height:31px; padding:0 11px; border:1px solid rgba(155,173,235,.25); border-radius:999px; color:rgba(231,235,253,.78); background:rgba(6,9,22,.46); box-shadow:0 8px 28px rgba(0,0,0,.18); font:11px system-ui; cursor:pointer; }
body[data-view="memory-universe"] .mu3-tools button:hover { color:#fff2d5; border-color:rgba(239,211,160,.42); }
body[data-view="memory-universe"] .mu3-tools .mu3-legend-toggle { width:32px; padding:0; color:#e7edff; font-size:16px; font-weight:650; line-height:1; }
body[data-view="memory-universe"] .mu3-legend-panel,body[data-view="memory-universe"] .mu3-management { position:fixed; z-index:45; color:#edf1ff; border:1px solid rgba(161,178,239,.25); background:rgba(7,10,25,.76); box-shadow:0 20px 72px rgba(0,0,0,.42); backdrop-filter:blur(18px); }
body[data-view="memory-universe"] .mu3-legend-panel { top:calc(env(safe-area-inset-top) + 122px); left:20px; width:270px; padding:13px; border-radius:16px; }
body[data-view="memory-universe"] .mu3-legend-panel header,body[data-view="memory-universe"] .mu3-management header { display:flex; align-items:center; justify-content:space-between; gap:10px; }
body[data-view="memory-universe"] .mu3-legend-panel header strong,body[data-view="memory-universe"] .mu3-management header strong { font-size:13px; font-weight:650; }
body[data-view="memory-universe"] .mu3-panel-close { width:26px; height:26px; padding:0; border:0; border-radius:50%; color:#bfc8ed; background:rgba(152,166,220,.12); font-size:17px; cursor:pointer; }
body[data-view="memory-universe"] .mu3-legend-list { display:grid; gap:7px; margin-top:10px; }
body[data-view="memory-universe"] .mu3-legend-item { display:grid; grid-template-columns:33px 1fr; align-items:center; gap:7px; min-height:30px; }
body[data-view="memory-universe"] .mu3-legend-item img { width:31px; height:31px; object-fit:contain; }
body[data-view="memory-universe"] .mu3-legend-task img { filter:hue-rotate(-26deg) saturate(1.08) brightness(1.12); }
body[data-view="memory-universe"] .mu3-legend-diary img { opacity:.58; filter:saturate(.32) brightness(.62); }
body[data-view="memory-universe"] .mu3-legend-pending img { opacity:.52; filter:saturate(.3) brightness(.66); }
body[data-view="memory-universe"] .mu3-legend-future img { opacity:.84; filter:saturate(.76) brightness(.82); }
body[data-view="memory-universe"] .mu3-legend-item span { display:grid; gap:1px; }
body[data-view="memory-universe"] .mu3-legend-item strong { font-size:11px; font-weight:600; }
body[data-view="memory-universe"] .mu3-legend-item small,body[data-view="memory-universe"] .mu3-legend-note,body[data-view="memory-universe"] .mu3-legend-demo { color:rgba(199,208,238,.63); font-size:10px; line-height:1.4; }
body[data-view="memory-universe"] .mu3-legend-note { margin:11px 0 0; padding-top:9px; border-top:1px solid rgba(165,178,229,.14); }
body[data-view="memory-universe"] .mu3-legend-demo { margin:7px 0 0; color:rgba(237,214,165,.66); }
body[data-view="memory-universe"] .mu3-management { top:calc(env(safe-area-inset-top) + 74px); right:20px; width:min(360px,calc(100vw - 40px)); max-height:calc(100dvh - 170px); overflow:auto; padding:16px; border-radius:18px; }
body[data-view="memory-universe"] .mu3-management header small { display:block; margin-top:3px; color:rgba(197,207,238,.56); font-size:10px; }
body[data-view="memory-universe"] .mu3-management-filter { display:grid; grid-template-columns:1fr 122px; gap:7px; margin:13px 0 10px; }
body[data-view="memory-universe"] .mu3-management input,body[data-view="memory-universe"] .mu3-management select,body[data-view="memory-universe"] .mu3-management textarea { box-sizing:border-box; width:100%; border:1px solid rgba(159,174,232,.22); border-radius:10px; color:#edf1ff; background:rgba(222,230,255,.07); font:12px system-ui; }
body[data-view="memory-universe"] .mu3-management input,body[data-view="memory-universe"] .mu3-management select { min-height:34px; padding:0 9px; }
body[data-view="memory-universe"] .mu3-management textarea { min-height:88px; margin-top:6px; padding:9px; resize:vertical; }
body[data-view="memory-universe"] .mu3-management-list { display:grid; gap:6px; }
body[data-view="memory-universe"] .mu3-management-list button { display:grid; gap:3px; width:100%; padding:10px; border:1px solid rgba(157,173,232,.14); border-radius:11px; color:#e8edff; background:rgba(173,185,241,.06); text-align:left; cursor:pointer; }
body[data-view="memory-universe"] .mu3-management-list button:hover { border-color:rgba(239,208,155,.32); background:rgba(197,172,238,.12); }
body[data-view="memory-universe"] .mu3-management-list span { overflow:hidden; font-size:12px; text-overflow:ellipsis; white-space:nowrap; }
body[data-view="memory-universe"] .mu3-management-list small,body[data-view="memory-universe"] .mu3-management-empty,body[data-view="memory-universe"] .mu3-management-limit { color:rgba(198,207,237,.6); font-size:10px; line-height:1.5; }
body[data-view="memory-universe"] .mu3-management-detail h3 { margin:7px 0 6px; font-size:17px; line-height:1.35; }
body[data-view="memory-universe"] .mu3-management-detail > p { color:#d7def8; font-size:12px; line-height:1.6; }
body[data-view="memory-universe"] .mu3-management-back { padding:0; border:0; color:#cfc9f4; background:transparent; font-size:11px; cursor:pointer; }
body[data-view="memory-universe"] .mu3-management dl { display:grid; gap:7px; margin:12px 0; }
body[data-view="memory-universe"] .mu3-management dl div { display:grid; grid-template-columns:68px 1fr; gap:8px; font-size:11px; }
body[data-view="memory-universe"] .mu3-management dt { color:rgba(188,199,234,.56); }.mu3-management dd { margin:0; color:#e4eafe; }
body[data-view="memory-universe"] .mu3-evidence-list { display:grid; gap:5px; margin:8px 0; }.mu3-evidence-list p { margin:0; padding:7px 8px; border-radius:9px; background:rgba(170,183,238,.07); font-size:10px; }.mu3-evidence-list small { display:block; margin-top:3px; color:rgba(202,211,241,.65); }
body[data-view="memory-universe"] .mu3-management-actions { display:flex; gap:7px; margin-top:12px; }.mu3-management-actions button,body[data-view="memory-universe"] .mu3-management-correction button { min-height:33px; padding:0 10px; border:1px solid rgba(169,183,239,.24); border-radius:10px; color:#eef2ff; background:rgba(145,127,208,.18); font:11px system-ui; cursor:pointer; }.mu3-management-actions .danger { color:#ffcbcb; background:rgba(169,73,94,.18); border-color:rgba(230,132,147,.26); }.mu3-management-correction { display:block; margin-top:12px; color:rgba(214,222,246,.78); font-size:11px; }

@media (max-width:760px) {
  body[data-view^="memory-universe"] .topbar { padding:calc(env(safe-area-inset-top) + 8px) 12px 8px; }
  body[data-view^="memory-universe"] .topbar .brand-mark { width:34px; height:34px; border-radius:11px; }
  body[data-view="memory-universe"] .mu3-topbar { top:calc(env(safe-area-inset-top) + 62px); }
  body[data-view="memory-universe"] .mu3-hint { display:none; }
  body[data-view="memory-universe"] .mu3-thread-strip { bottom:calc(env(safe-area-inset-bottom) + 82px); }
  body[data-view="memory-universe"] .mu3-detail { bottom:calc(env(safe-area-inset-bottom) + 132px); }
  body[data-view="memory-universe"] .mu3-tools { top:calc(env(safe-area-inset-top) + 62px); right:10px; }
  body[data-view="memory-universe"] .mu3-tools .mu3-legend-toggle { width:32px; padding:0; overflow:hidden; color:transparent; font-size:0; }
  body[data-view="memory-universe"] .mu3-tools .mu3-legend-toggle::before { content:"✦"; color:#e7edff; font-size:15px; }
body[data-view="memory-universe"] .mu3-tools .mu3-manage-toggle { padding-inline:9px; font-size:10px; }
body[data-view="memory-universe"] .mu3-detail-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:15px; }
body[data-view="memory-universe"] .mu3-detail-actions button { min-height:34px; padding:0 12px; border:1px solid rgba(181,193,238,.28); border-radius:10px; color:#eaf0ff; background:rgba(132,119,187,.2); font:11px system-ui; cursor:pointer; }
body[data-view="memory-universe"] .mu3-detail-actions button.primary { color:#22170a; border-color:rgba(255,224,169,.58); background:linear-gradient(135deg,#f1d29a,#c4975b); box-shadow:0 5px 18px rgba(196,151,91,.2); }
body[data-view="memory-universe"] .mu3-detail-actions button:disabled { opacity:.55; cursor:wait; }
body[data-view="memory-universe"] .mu3-detail-pending-status { color:#b6bfd4; }
body[data-view="memory-universe"] .mu3-detail-active-status { color:#f0c67e; }
body[data-view="memory-universe"] .mu3-detail-source-label { margin-top:13px; color:rgba(197,207,238,.6); font-size:11px; }
body[data-view="memory-universe"] .mu3-detail-relation { margin-top:8px; color:rgba(230,225,249,.82); font-size:12px; line-height:1.45; }
body[data-view="memory-universe"] .mu3-detail-date { margin-top:10px; color:rgba(181,192,224,.56); font:10px/1.4 ui-monospace,SFMono-Regular,Consolas,monospace; }
body[data-view="memory-universe"] .mu3-detail-note { margin-top:12px; color:rgba(214,222,246,.7); font-size:11px; line-height:1.55; }
body[data-view="memory-universe"] .mu3-story-section + .mu3-story-section { margin-top:12px; }
body[data-view="memory-universe"] .mu3-detail-source { margin-top:12px; padding:9px 10px; border-radius:10px; color:rgba(219,226,249,.78); background:rgba(172,185,238,.08); font-size:11px; line-height:1.55; white-space:pre-line; }
body[data-view="memory-universe"] .mu3-detail-error { margin:10px 0 0; color:#ffb7b7; font-size:11px; }
body[data-view="memory-universe"] .mu3-management-actions .danger { color:#eef2ff; background:rgba(145,127,208,.18); border-color:rgba(169,183,239,.24); }
  body[data-view="memory-universe"] .mu3-legend-panel,body[data-view="memory-universe"] .mu3-management { top:auto; right:0; bottom:0; left:0; width:auto; max-height:min(68dvh,620px); padding:18px 18px calc(env(safe-area-inset-bottom) + 18px); border-width:1px 0 0; border-radius:20px 20px 0 0; }
  body[data-view="memory-universe"] .mu3-legend-panel { z-index:52; }
  body[data-view="memory-universe"] .mu3-management { z-index:53; }
  body[data-view="memory-universe"] .mu3-management-filter { grid-template-columns:1fr 108px; }
}
@media (max-width: 680px) {
  .memory-star-map { min-height: 310px; }
  .memory-timeline-item { grid-template-columns: 68px minmax(0, 1fr); }
  .memory-timeline-item small { grid-column: 2; }
  .relationship-suggestion, .relationship-stage-control { align-items: stretch; flex-direction: column; }
  .relationship-suggestion button, .relationship-stage-control button { width: 100%; }
}

/* History: document scroll stays available; only the session rail is bounded. */
@media (min-width: 761px) { #historyPanel .history-layout { max-height: none; overflow: visible; } #historyPanel .history-detail { overflow: visible; } #historyPanel .history-sidebar { max-height: 620px; overflow-y: auto; } }


/* Desktop history: one fixed work area, two independent scroll columns. */
@media (min-width: 761px) {
  #historyPanel.active {
    display: flex !important;
    flex-direction: column;
    height: calc(100dvh - 84px - 68px - 40px);
    max-height: none !important;
    min-height: 0;
    overflow: hidden !important;
  }
  #historyPanel .history-layout {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none !important;
    overflow: hidden !important;
  }
  #historyPanel .history-sidebar,
  #historyPanel .history-detail {
    min-height: 0;
    max-height: none !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }
  #historyPanel .history-detail { overflow-x: hidden; }
  #historyPanel .history-detail-empty,
  #historyPanel .history-message-list { min-height: 100%; }
}


/* Desktop history is a fixed workspace: no document-level third scrollbar. */
#appView[data-active-panel]:not([data-active-panel="home"]) .welcome-row,
#appView[data-active-panel]:not([data-active-panel="home"]) #deviceSwitcher {
  display: none;
}
@media (min-width: 761px) {
  body:has(#appView[data-active-panel="history"]) {
    height: 100dvh;
    overflow: hidden;
  }
  body:has(#appView[data-active-panel="history"]) .topbar {
    display: none;
  }
  body:has(#appView[data-active-panel="history"]) .shell {
    height: 100dvh;
    margin: 0 auto;
    padding: 18px 0 86px;
    overflow: hidden;
  }
  body:has(#appView[data-active-panel="history"]) #appView {
    height: 100%;
    padding-bottom: 0;
  }
  #appView[data-active-panel="history"] #historyPanel.active {
    height: 100%;
    max-height: none !important;
  }
  #appView[data-active-panel="history"] #historyPanel .panel-heading {
    margin-top: 0;
  }
}


/* The dashboard welcome area belongs to Home only. */
#appView:has(#rolesPanel.active) .welcome-row,
#appView:has(#rolesPanel.active) #deviceSwitcher,
#appView:has(#devicePanel.active) .welcome-row,
#appView:has(#devicePanel.active) #deviceSwitcher,
#appView:has(#servicePanel.active) .welcome-row,
#appView:has(#servicePanel.active) #deviceSwitcher,
#appView:has(#historyPanel.active) .welcome-row,
#appView:has(#historyPanel.active) #deviceSwitcher,
#appView:has(#memoryPanel.active) .welcome-row,
#appView:has(#memoryPanel.active) #deviceSwitcher,
#appView:has(#helpPanel.active) .welcome-row,
#appView:has(#helpPanel.active) #deviceSwitcher {
  display: none !important;
}
#voiceQuotaDeviceList { display: none !important; }


/* Performance pass: avoid full-page repaints during navigation and scrolling. */
@media (min-width: 761px) {
  .ambient { display: none; }
  .surface,
  .topbar,
  .bottom-nav,
  .history-conversation-heading,
  .role-badge,
  dialog::backdrop {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  .panel.active {
    animation-duration: 140ms;
    will-change: opacity, transform;
  }
  .quick-card,
  .memory-count-card,
  .role-cover img,
  .toggle-track,
  .diy-custom-toggle i,
  .diy-custom-toggle i::after {
    transition-duration: 120ms;
  }
  .quick-card,
  .memory-count-card,
  .role-card,
  .history-message,
  .history-session {
    contain: paint;
  }
}


/* Mobile history uses a list-to-detail flow, not two stacked scroll regions. */
.history-conversation-actions { display: flex; align-items: center; gap: 8px; }
@media (max-width: 760px) {
  #historyPanel .history-layout { display: block; min-height: 0; }
  #historyPanel:not(.mobile-history-detail) .history-sidebar,
  #historyPanel:not(.mobile-history-detail) .history-session-list { max-height: none; overflow: visible; }
  #historyPanel:not(.mobile-history-detail) .history-sidebar { padding: 8px 0 14px; border: 0; background: transparent; }
  #historyPanel:not(.mobile-history-detail) .history-detail { display: none; }
  #historyPanel.mobile-history-detail .history-heading,
  #historyPanel.mobile-history-detail .history-privacy,
  #historyPanel.mobile-history-detail .history-sidebar { display: none; }
  #historyPanel.mobile-history-detail .history-detail { display: block; overflow: visible; background: transparent; }
  #historyPanel.mobile-history-detail .history-conversation-heading { position: sticky; top: 0; padding: 12px 0 16px; background: var(--bg); }
  #historyPanel.mobile-history-detail .history-conversation-heading h3 { font-size: 20px; }
  #historyPanel.mobile-history-detail .history-message-list { min-height: 0; padding: 8px 0 110px; }
  #historyPanel.mobile-history-detail .history-message { max-width: 92%; }
  .history-conversation-actions { gap: 6px; }
  .history-back-button { white-space: nowrap; }
}


/* Scalable role library: compact cards that make room for a growing catalogue. */
.role-grid {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.role-card { border-radius: 22px; }
.role-cover {
  height: auto;
  aspect-ratio: 16 / 9;
}
.role-badge { left: 12px; top: 12px; padding: 5px 9px; }
.role-body { padding: 17px 18px 18px; }
.role-body h3 { margin: 0; font-size: 23px; line-height: 1.25; }
.role-body p { margin: 9px 0 0; font-size: 13px; line-height: 1.6; }
.role-tags { gap: 6px; margin: 12px 0; }
.role-tags span { padding: 4px 8px; font-size: 10px; }
.role-actions button { min-height: 42px; font-size: 13px; }
@media (max-width: 760px) {
  .role-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .role-cover { aspect-ratio: 4 / 3; }
  .role-body { padding: 14px; }
  .role-body h3 { font-size: 19px; }
  .role-body p { font-size: 12px; }
  .role-tags { margin: 10px 0; }
  .role-actions { gap: 6px; }
  .role-actions button { min-height: 38px; padding: 0 8px; font-size: 12px; }
}
@media (max-width: 520px) {
  .role-grid { grid-template-columns: 1fr; }
  .role-cover { aspect-ratio: 16 / 9; }
  .role-body { padding: 17px; }
  .role-body h3 { font-size: 22px; }
  .role-body p { font-size: 13px; }
}


/* Keep role actions on one shared baseline despite different copy lengths. */
.role-card { display: flex; flex-direction: column; }
.role-body { display: flex; flex: 1 1 auto; flex-direction: column; }
.role-actions { margin-top: auto; }
.role-actions > button { min-height: 42px; }

/* Role Library Mobile UI Polish V1 — scoped overrides for the library only. */
.role-filter-wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: -4px 0 20px; }
.role-filters { display: flex; min-width: 0; gap: 8px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.role-filters::-webkit-scrollbar { display: none; }
.role-filter { flex: 0 0 auto; min-height: 36px; padding: 0 14px; border: 1px solid var(--line); color: var(--muted); background: rgba(255,255,255,.5); border-radius: 999px; font-size: 13px; white-space: nowrap; }
.role-filter.active { border-color: transparent; color: #fff; background: var(--accent); }
.owned-filter { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 7px; margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; }
.owned-filter input { width: 17px; min-width: 17px; min-height: 17px; margin: 0; accent-color: var(--accent); }
.role-card { min-width: 0; }
.role-cover { height: auto; aspect-ratio: 4 / 3; }
.role-cover img { display: block; max-width: 100%; }
.role-description { display: -webkit-box; min-height: 3.2em; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.role-tags { flex-wrap: nowrap; min-height: 28px; overflow: hidden; }
.role-tags span { flex: 0 0 auto; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell { margin-bottom: calc(120px + env(safe-area-inset-bottom)); }

@media (max-width: 760px) {
  .topbar, .shell { width: min(calc(100% - 28px), 600px); }
}

@media (max-width: 640px) {
  .role-filter-wrap { display: block; margin-bottom: 16px; }
  .role-filters { margin-right: -14px; padding: 1px 14px 1px 0; }
  .owned-filter { margin-top: 12px; }
  .role-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .role-card { border-radius: 18px; }
  .role-cover { aspect-ratio: 4 / 3; }
  .role-badge { left: 9px; top: 9px; padding: 4px 7px; font-size: 10px; }
  .role-body { min-width: 0; padding: 13px; }
  .role-body h3 { margin-bottom: 5px; font-size: clamp(18px, 5vw, 22px); line-height: 1.25; }
  .role-description { min-height: 3em; margin-top: 0; font-size: 12px; line-height: 1.5; }
  .role-tags { min-height: 25px; margin: 10px 0; gap: 5px; }
  .role-tags span { padding: 4px 7px; font-size: 10px; }
  .role-actions { gap: 6px; }
  .role-actions button { min-width: 0; min-height: 36px; padding: 0 8px; border-radius: 11px; font-size: 12px; white-space: nowrap; }
}


/* Device support library. */
.device-resources { margin-top: 16px; padding: 22px; border-radius: 24px; }
.device-resources h3 { margin: 4px 0 16px; font-family: "Songti SC", serif; font-size: 25px; font-weight: 500; }
.device-resource-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.device-resource-links a { min-height: 78px; padding: 15px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--ink); background: rgba(245,241,235,.8); border: 1px solid var(--line); border-radius: 16px; font-size: 13px; font-weight: 700; text-decoration: none; }
.device-resource-links a:hover { color: var(--accent); border-color: rgba(141,38,55,.3); }
.device-resource-links span { color: var(--accent); font-size: 18px; }
.device-recovery-note { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.device-recovery-note summary { cursor: pointer; color: var(--accent); font-weight: 700; }
.device-recovery-note p { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
@media (max-width: 760px) {
  .device-resources { padding: 18px; }
  .device-resources h3 { font-size: 22px; }
  .device-resource-links { grid-template-columns: 1fr; }
  .device-resource-links a { min-height: 58px; }
}

/* Customer policy previews: concise, readable, and intentionally marked as drafts. */
.device-resources-intro { margin: -8px 0 16px; color: var(--muted); font-size: 13px; }
.device-resource-links button { min-height: 78px; padding: 15px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--ink); background: rgba(245,241,235,.8); border: 1px solid var(--line); border-radius: 16px; font: inherit; font-size: 13px; font-weight: 700; text-align: left; cursor: pointer; }
.device-resource-links button:hover, .device-resource-links button:focus-visible { color: var(--accent); border-color: rgba(141,38,55,.3); }
.policy-dialog { width: min(720px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); }
.policy-dialog-card { max-height: calc(100dvh - 28px); overflow: auto; }
.policy-dialog-notice { margin: 12px 0 18px; padding: 11px 13px; color: #7b5430; background: #fff3df; border: 1px solid #f0d5ae; border-radius: 12px; font-size: 13px; line-height: 1.6; }
.policy-dialog-body { display: grid; gap: 12px; }
.policy-dialog-body section { padding: 16px; border: 1px solid var(--line); background: rgba(250,247,242,.78); border-radius: 16px; }
.policy-dialog-body h3 { margin: 0 0 8px; font-size: 16px; }
.policy-dialog-body p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.75; }
.policy-dialog-actions { grid-template-columns: 1fr; }
@media (max-width: 760px) { .device-resource-links button { min-height: 58px; } .policy-dialog { width: 100%; max-width: 100%; margin: auto 0 0; border: 0; border-radius: 22px 22px 0 0; } .policy-dialog-card { border-radius: 22px 22px 0 0; padding: 26px 20px; } }


/* Account recovery controls share the existing compact topbar style. */
.topbar-actions { display: inline-flex; align-items: center; gap: 9px; }
@media (max-width: 410px) { .topbar-actions { gap: 6px; } .topbar-actions .ghost { padding-inline: 10px; } }

.role-rate-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.role-rate-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.role-rate-value {
  min-width: 72px;
  font-weight: 600;
  text-align: right;
  color: var(--accent, #5b8cff);
}
#roleTtsRateInput {
  flex: 1;
}
.role-voice-row { display: grid; gap: 7px; margin-top: 16px; }
.relationship-style-settings { margin-top: 22px; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.relationship-style-settings h3 { margin: 0 0 6px; color: var(--ink); font-size: 14px; font-weight: 650; }
.relationship-style-settings > .muted { margin: 0; font-size: 12px; line-height: 1.55; }
.relationship-style-settings label { display: grid; gap: 7px; margin-top: 14px; color: var(--ink); font-size: 13px; font-weight: 650; }
.relationship-style-settings textarea { width: 100%; min-height: 76px; box-sizing: border-box; resize: vertical; }
.relationship-style-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.relationship-style-preset { min-height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: #fff; font: inherit; font-size: 13px; cursor: pointer; }
.relationship-style-preset:hover, .relationship-style-preset[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: rgba(141,38,55,.07); }
.relationship-style-preset:focus-visible { outline: 3px solid rgba(141,38,55,.18); outline-offset: 2px; }
.role-voice-controls { display: flex; align-items: center; gap: 10px; }
.role-voice-controls select { width: 100%; min-width: 0; height: 42px; padding: 0 34px 0 12px; border: 1px solid var(--line); color: var(--ink); background: #fff; border-radius: 12px; font: inherit; cursor: pointer; }
.role-voice-controls select:focus-visible { outline: 3px solid rgba(141,38,55,.18); outline-offset: 1px; border-color: var(--accent); }
.role-voice-controls .diy-voice-preview { width: 36px; height: 36px; }
.role-voice-controls select:disabled, .role-voice-controls .diy-voice-preview:disabled { opacity: .55; cursor: not-allowed; }
.role-image-settings { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.role-image-settings h3 { margin: 0 0 11px; color: var(--ink); font-size: 14px; font-weight: 650; }
.role-image-row { display: flex; align-items: center; gap: 14px; }
.role-image-preview-wrap { width: 112px; height: 84px; flex: 0 0 auto; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); background: #f3eeea; border-radius: 13px; color: var(--muted); }
.role-image-preview-wrap img { width: 100%; height: 100%; object-fit: cover; }
.role-image-preview-wrap span { font-size: 28px; font-weight: 650; }
.role-image-actions { min-width: 0; display: grid; justify-items: start; gap: 6px; }
.role-image-actions .ghost { min-height: 38px; padding: 0 14px; }
.role-image-actions small { color: var(--muted); font-size: 12px; }
.role-image-actions .text-button { padding: 0; border: 0; color: var(--accent); background: transparent; font: inherit; font-size: 12px; cursor: pointer; }
.role-image-actions .text-button:hover, .role-image-actions .text-button:focus-visible { text-decoration: underline; }
.device-image-crop-dialog { width: min(500px, calc(100vw - 28px)); padding: 0; border: 0; background: transparent; }
.device-image-crop-form { margin: 0; padding: 26px 24px 22px; border: 1px solid rgba(255,255,255,.8); background: #fffdf9; border-radius: 24px; box-shadow: 0 30px 90px rgba(20,17,16,.25); }
.device-image-crop-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.device-image-crop-header .eyebrow { margin: 0 0 4px; }
.device-image-crop-header h2 { margin: 0; }
.device-image-crop-close { width: 36px; height: 36px; padding: 0; border: 0; color: var(--muted); background: transparent; border-radius: 50%; font-size: 24px; cursor: pointer; }
.device-image-crop-intro { margin: 14px 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.device-image-crop-modal-viewport { position: relative; width: 240px; height: 240px; max-width: 100%; margin: 0 auto; overflow: hidden; border: 2px solid var(--accent); border-radius: 14px; background: #10121a; cursor: grab; touch-action: none; box-shadow: 0 0 0 4px rgba(141,38,55,.12); }
.device-image-crop-modal-viewport:active { cursor: grabbing; }
.device-image-crop-modal-image { position: absolute; max-width: none; user-select: none; pointer-events: none; }
.device-image-crop-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.device-image-crop-actions button { min-height: 40px; padding-inline: 16px; }

/* ==========================================================================
   Home · 我们之间 (v1). Keeps main's wine accent, serif titles, role portrait
   and fixed bottom nav. Scoped to the top bar account menu, the Home header
   and #homePanel.
   ========================================================================== */

/* Account menu: id, change password and logout live behind one button. */
.account-menu-wrap { position: relative; }
.account-button { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 12px 0 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: rgba(255,255,255,.62); font-size: 13px; }
.account-avatar { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-size: 12px; }
.account-caret { color: var(--muted); font-size: 11px; }
.account-menu { position: absolute; z-index: 60; right: 0; top: calc(100% + 8px); min-width: 200px; padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-solid); box-shadow: 0 18px 48px rgba(51,38,32,.18); }
.account-menu-id { margin: 6px 10px 8px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.account-menu-id:empty { display: none; }
.account-menu button { display: block; width: 100%; min-height: 42px; padding: 0 10px; border: 0; border-radius: 12px; color: var(--ink); background: transparent; text-align: left; }
.account-menu button:hover, .account-menu button:focus-visible { background: rgba(141,38,55,.06); }
.account-menu .account-menu-logout { color: #9a2538; }

/* Home header: greeting and the one device status pill share a quiet row. */
.welcome-row.home-intro { align-items: center; margin: 0 0 14px; }
#appView > .welcome-row.home-intro { z-index: 5; } /* dropdowns above the hero */
.welcome-row.home-intro h1 { font-size: clamp(26px, 4vw, 34px); }
.home-intro .device-switcher { position: relative; margin: 0; overflow: visible; }
.device-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; color: #4f4b46; background: rgba(255,255,255,.62); font-size: 13px; white-space: nowrap; }
button.device-pill { cursor: pointer; }
.device-pill-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #62b383; }
.device-pill.offline .device-pill-dot, .device-pill-dot.off { background: #a8aaa7; }
.device-pill-caret { margin-left: 2px; color: var(--muted); font-size: 11px; }
.device-menu { position: absolute; z-index: 60; right: 0; top: calc(100% + 8px); width: 240px; padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-solid); box-shadow: 0 18px 48px rgba(51,38,32,.18); }
.device-menu-item { display: flex; align-items: center; gap: 9px; width: 100%; min-height: 44px; padding: 0 10px; border: 0; border-radius: 12px; color: var(--ink); background: transparent; font-size: 13px; text-align: left; }
.device-menu-item small { margin-left: auto; color: var(--muted); font-size: 11px; }
.device-menu-item.current { background: rgba(141,38,55,.06); }
.device-menu-settings { margin-top: 6px; border-top: 1px solid var(--line); border-radius: 0 0 12px 12px; }

/* Hero: the role portrait is the page. Its height leaves room for the top bar
   and the fixed bottom nav, so the role actions are never under the nav. */
#homePanel .home-hero { position: relative; display: block; min-height: 0; overflow: hidden; border-radius: 28px; background: #2a1c1d; }
#homePanel .home-hero .character-art { width: 100%; height: clamp(280px, calc(100vh - 290px), 560px); height: clamp(280px, calc(100svh - 290px), 560px); object-fit: cover; object-position: 50% 28%; }
#homePanel .home-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20,12,13,0) 36%, rgba(24,14,15,.82) 100%); pointer-events: none; }
#homePanel .home-hero .character-copy { position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; padding: 22px 20px 20px; color: #fff; }
#homePanel .home-hero .eyebrow { color: rgba(255,236,236,.82); }
#homePanel .home-hero h2 { margin: 0 0 4px; color: #fff; font-size: clamp(32px, 5vw, 46px); line-height: 1.12; }
#homePanel .home-hero .role-tagline { min-height: 0; margin: 0 0 16px; color: rgba(255,255,255,.86); font-size: 14px; }
#homePanel .home-hero .hero-actions { flex-direction: row; margin-top: 0; }
#homePanel .home-hero .hero-actions button { flex: 1; width: auto; }
#homePanel .home-hero .ghost { color: #fff; border-color: rgba(255,255,255,.45); background: rgba(255,255,255,.1); }

/* 我们之间: one conversation, one confirmed memory, each a way in. */
#homePanel .home-card { margin-top: 16px; padding: 22px 20px 8px; border-radius: 26px; }
#homePanel .home-card h3 { margin: 0 0 6px; font-family: "Songti SC", "STSong", serif; font-size: 22px; font-weight: 500; }
#homePanel .home-bind-card { padding-bottom: 22px; }
#homePanel .home-bind-card p:not(.eyebrow) { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.home-trace { display: block; width: 100%; min-height: 72px; padding: 14px 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; color: var(--ink); background: transparent; text-align: left; }
.home-trace:disabled { cursor: default; opacity: 1; }
.home-trace-label { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.home-trace-link { flex: none; color: var(--accent); }
.home-trace-text { display: block; margin-top: 6px; font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.home-trace[data-state="empty"] .home-trace-text,
.home-trace[data-state="error"] .home-trace-text { color: var(--muted); font-size: 13px; line-height: 1.65; }
.home-trace[data-state="loading"] .home-trace-text { height: 38px; background: linear-gradient(#eee7e1, #eee7e1) 0 4px / 40% 12px no-repeat, linear-gradient(#f2ece6, #f2ece6) 0 24px / 86% 14px no-repeat; }

#homePanel .home-quick { margin-top: 16px; grid-template-columns: 1fr 1fr; gap: 10px; }
#homePanel .home-quick .quick-card { min-height: 76px; padding: 14px; align-items: center; }

/* The last Home block always clears the fixed bottom nav and the safe area. */
#appView:has(#homePanel.active) { padding-bottom: calc(124px + env(safe-area-inset-bottom)); }

@media (max-width: 410px) {
  #homePanel .home-quick { grid-template-columns: 1fr 1fr; }
  #homePanel .home-quick .quick-card { padding: 12px; gap: 10px; }
  #homePanel .home-quick .quick-icon { width: 36px; height: 36px; }
}

@media (min-width: 1024px) {
  #homePanel .home-layout { display: grid; grid-template-columns: minmax(380px, 5fr) 6fr; gap: 24px; align-items: start; }
  #homePanel .home-hero { position: sticky; top: 16px; }
  #homePanel .home-hero .character-art { height: calc(100vh - 290px); min-height: 420px; }
  #homePanel .home-hero .hero-actions button { flex: 0 0 auto; }
  #homePanel .home-card, #homePanel .home-quick { margin-top: 0; }
  #homePanel .home-side { display: grid; gap: 16px; }
}

/* ==========================================================================
   Role library · 剧照目录 (B1). A contact sheet of stills and one open spread.
   Scoped to #rolesPanel; keeps main's wine accent, serif and fixed bottom nav.
   --role-tint-h/s come from the selected role's cover (fallback: wine).
   ========================================================================== */
#rolesPanel { --role-tint-h: 350; --role-tint-s: 45%; --role-ease: cubic-bezier(.2,.7,.2,1); --role-spring: cubic-bezier(.34,1.56,.64,1); position: relative; }
#rolesPanel::before { content: ""; position: fixed; z-index: -1; inset: 0 0 auto; height: 62vh; background: linear-gradient(180deg, hsl(var(--role-tint-h) var(--role-tint-s) 92% / .85), transparent); pointer-events: none; transition: background .6s var(--role-ease); }
#rolesPanel .panel-heading { margin: 12px 0 10px; }
#rolesPanel .panel-heading h2 { margin: 0; font-size: 26px; }
#rolesPanel .panel-heading > p { margin: 4px 0 0; font-size: 13px; }

/* Filters: quiet text tabs + one switch on the same row. */
#rolesPanel .role-filter-wrap { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; }
#rolesPanel .role-filters { flex: 1; gap: 18px; margin: 0; padding: 0 0 2px; }
#rolesPanel .role-filter { position: relative; min-height: 36px; padding: 0 2px; border: 0; border-radius: 0; color: var(--muted); background: none; font-size: 14px; }
#rolesPanel .role-filter.active { color: var(--ink); background: none; font-weight: 600; }
#rolesPanel .role-filter.active::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: 3px; height: 2px; border-radius: 2px; background: var(--accent); }
#rolesPanel .owned-filter { margin: 0; gap: 6px; font-size: 12px; }
#rolesPanel .owned-filter input { width: 30px; min-width: 30px; height: 18px; min-height: 18px; margin: 0; padding: 0; appearance: none; -webkit-appearance: none; position: relative; border: 0; border-radius: 999px; background: #d8d4d0; cursor: pointer; transition: background .2s; }
#rolesPanel .owned-filter input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .22s var(--role-spring); }
#rolesPanel .owned-filter input:checked { background: var(--accent); }
#rolesPanel .owned-filter input:checked::after { transform: translateX(12px); }
#rolesPanel .owned-filter input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.role-library-notice { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; padding: 10px 14px; border-radius: 14px; color: #5c554f; background: rgba(255,255,255,.62); font-size: 12px; line-height: 1.5; }
.role-library-notice button { flex: none; min-height: 32px; padding: 0 4px; border: 0; color: var(--accent); background: none; font-size: 12px; font-weight: 600; }
.role-library-empty { margin: 24px 0; padding: 22px; border-radius: 20px; color: var(--muted); background: rgba(255,255,255,.6); font-size: 13px; line-height: 1.7; text-align: center; }

/* Contact sheet: every still is a 44px+ tap target; the strip scrolls sideways. */
.role-contact { display: flex; gap: 10px; margin: 0 -14px 12px; padding: 4px 14px 8px; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: none; }
.role-contact::-webkit-scrollbar { display: none; }
.role-still { flex: none; width: 58px; padding: 0; border: 0; color: var(--ink); background: none; text-align: center; scroll-snap-align: center; transition: transform .25s var(--role-spring); }
.role-still-frame { position: relative; display: block; width: 58px; height: 76px; overflow: hidden; border-radius: 12px; background: hsl(350 22% 90%); box-shadow: 0 0 0 1px rgba(60,50,45,.08); transition: box-shadow .25s, transform .25s var(--role-spring); }
.role-still img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 28%; }
.role-still-glyph { display: grid; height: 100%; place-items: center; color: rgba(60,50,45,.45); font-family: "Songti SC", "STSong", serif; font-size: 28px; }
.role-still small { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.role-still.is-locked img { filter: grayscale(.8) brightness(.96); }
.role-still.is-locked .role-still-frame::after { content: "未拥有"; position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 0; color: #fff; background: rgba(60,56,52,.62); font-size: 9px; }
.role-still.is-current .role-still-frame::before, .role-still.is-last .role-still-frame::before { content: ""; position: absolute; z-index: 1; left: 5px; top: 5px; width: 9px; height: 9px; border: 2px solid #fff; border-radius: 50%; background: var(--accent); }
.role-still.is-last .role-still-frame::before { background: #8a837c; }
.role-still[aria-selected="true"] { transform: translateY(-3px); }
.role-still[aria-selected="true"] .role-still-frame { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent), 0 12px 20px -10px rgba(141,38,55,.5); }
.role-still[aria-selected="true"] small { color: var(--ink); font-weight: 600; }
.role-still:active .role-still-frame { transform: scale(.94); }
.role-still:focus-visible { outline: none; }
.role-still:focus-visible .role-still-frame { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }

/* Spread: photo plate, vertical serif name, quote, sticky actions. */
.role-spread { position: relative; overflow: clip; padding: 14px 14px 16px; border-radius: 28px; background: rgba(255,253,249,.94); box-shadow: 0 24px 60px -30px hsl(var(--role-tint-h) 40% 25% / .5); touch-action: pan-y; }
.role-spread img, .role-contact img { -webkit-user-drag: none; user-select: none; }
.role-spread-water { position: absolute; right: -18px; bottom: -40px; color: hsl(var(--role-tint-h) 35% 45% / .07); font-family: "Songti SC", "STSong", serif; font-size: 200px; line-height: 1; pointer-events: none; }
.role-spread-top { display: grid; grid-template-columns: minmax(0, 1fr) 62px; gap: 12px; }
.role-plate { position: relative; height: clamp(200px, calc(100vh - 560px), 380px); height: clamp(200px, calc(100svh - 560px), 380px); overflow: hidden; padding: 0; border: 0; border-radius: 18px; background: #2a1c1d; cursor: zoom-in; }
.role-plate:disabled { cursor: default; }
.role-plate-backdrop { position: absolute; inset: -20px; width: calc(100% + 40px); height: calc(100% + 40px); object-fit: cover; filter: blur(20px); opacity: .9; }
.role-plate-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 28%; }
.role-spread.is-locked .role-plate-photo { filter: grayscale(.5); }
.role-plate-glyph { display: none; }
.role-plate.is-empty { background: linear-gradient(160deg, hsl(var(--role-tint-h) 30% 93%), hsl(var(--role-tint-h) 30% 83%)); }
.role-plate.is-empty img { display: none; }
.role-plate.is-empty .role-plate-glyph { position: absolute; inset: 0; display: grid; place-items: center; color: hsl(var(--role-tint-h) 30% 40% / .25); font-family: "Songti SC", "STSong", serif; font-size: 120px; }
.role-name-col { display: flex; flex-direction: column; align-items: center; justify-content: space-between; min-height: 0; padding: 6px 0; }
.role-vname { display: flex; flex-direction: column; align-items: center; margin: 0; color: var(--ink); font-family: "Songti SC", "STSong", serif; font-size: 34px; font-weight: 500; line-height: 1.12; }
.role-vname span { display: block; }
.role-vname .is-dot { line-height: .6; }
.role-vname.is-long { font-size: 27px; }
.role-vtags { display: flex; flex-direction: column; align-items: center; gap: 1px; color: hsl(var(--role-tint-h) 35% 35%); font-size: 11px; line-height: 1.25; }
/* Names longer than 7 characters read horizontally under the photo. */
.role-spread.is-long-name .role-spread-top { grid-template-columns: minmax(0, 1fr); }
.role-spread.is-long-name .role-name-col { flex-direction: row; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; padding: 12px 2px 0; }
.role-spread.is-long-name .role-vname { display: block; font-size: 26px; line-height: 1.3; overflow-wrap: anywhere; }
.role-spread.is-long-name .role-vname span { display: inline; }
.role-spread.is-long-name .role-vtags { flex-direction: row; }

/* 陪伴中 seal: a wine chop on the photo, stamped only after a real switch. */
.role-seal { position: absolute; right: 10px; bottom: 10px; display: grid; place-content: center; width: 58px; height: 58px; border: 2px solid rgba(255,255,255,.85); border-radius: 50%; color: #fff; background: rgba(141,38,55,.9); font-family: "Songti SC", "STSong", serif; font-size: 13px; line-height: 1.15; text-align: center; transform: rotate(-12deg); box-shadow: 0 6px 16px rgba(0,0,0,.25); }
.role-seal span { display: block; }
.role-seal.is-last { background: rgba(120,110,100,.86); }
.role-seal.is-locked { background: rgba(90,86,82,.84); }
.role-seal.is-stamping { animation: role-stamp .6s var(--role-spring) both; }
@keyframes role-stamp { 0% { opacity: 0; transform: rotate(-32deg) scale(2.2); } 60% { opacity: 1; transform: rotate(-10deg) scale(.9); } 100% { transform: rotate(-12deg) scale(1); } }

.role-quote { position: relative; display: -webkit-box; margin: 14px 2px 4px; padding-left: 30px; overflow: hidden; color: #3f3a36; font-family: "Songti SC", "STSong", serif; font-size: 16px; line-height: 1.7; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; }
.role-quote:empty { display: none; }
.role-quote::before { content: "“"; position: absolute; left: -2px; top: -14px; color: hsl(var(--role-tint-h) 45% 40% / .55); font-size: 54px; }
.role-spread-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 12px; color: var(--muted); font-size: 12px; }
.role-folio { flex: none; font-family: "Songti SC", "STSong", serif; letter-spacing: .1em; }
.role-spread-actions { position: sticky; z-index: 2; bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; gap: 10px; margin: 0 -14px -16px; padding: 12px 14px 16px; background: linear-gradient(180deg, rgba(255,253,249,0), rgba(255,253,249,.97) 10px); }
.role-spread-actions .select-role { flex: 1; min-height: 46px; }
.role-spread-actions .select-role:disabled { cursor: default; opacity: .75; }

/* Turning to another still. */
.role-spread.is-turning .role-spread-top { animation: role-turn-in .42s var(--role-ease) backwards; }
.role-spread.is-turning.from-left .role-spread-top { animation-name: role-turn-in-left; }
.role-spread.is-turning .role-quote, .role-spread.is-turning .role-spread-meta { animation: role-fade-up .42s var(--role-ease) .06s backwards; }
.role-spread.is-turning .role-vname { animation: role-name-in .6s var(--role-ease) .08s backwards; }
@keyframes role-turn-in { from { opacity: 0; transform: translateX(22px); } }
@keyframes role-turn-in-left { from { opacity: 0; transform: translateX(-22px); } }
@keyframes role-fade-up { from { opacity: 0; transform: translateY(8px); } }
@keyframes role-name-in { from { opacity: 0; transform: translateY(-12px); } }

/* Full image, uncropped. */
.role-image-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; padding: 0; border: 0; background: transparent; }
.role-image-dialog[open] { display: grid; place-items: center; }
.role-image-dialog::backdrop { background: rgba(15,10,10,.9); }
.role-image-dialog img { max-width: 94vw; max-height: 86dvh; border-radius: 12px; cursor: zoom-out; }
.role-image-close { position: fixed; right: 14px; top: calc(14px + env(safe-area-inset-top)); width: 44px; height: 44px; border: 0; border-radius: 50%; color: #fff; background: rgba(255,255,255,.16); font-size: 24px; }

@media (min-width: 900px) {
  .role-contact { margin: 0 0 16px; padding: 4px 2px 10px; }
  .role-still { width: 72px; }
  .role-still-frame { width: 72px; height: 94px; }
  /* Desktop: photo + vertical name on the left; quote, status, actions on the right. */
  .role-spread { display: grid; max-width: 980px; padding: 22px; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); grid-template-rows: 1fr auto auto; grid-template-areas: "top quote" "top meta" "top actions"; column-gap: 30px; }
  .role-spread-top { grid-area: top; grid-template-columns: minmax(0, 1fr) 92px; gap: 16px; }
  .role-plate { height: clamp(250px, calc(100vh - 545px), 460px); }
  #rolesPanel::before { display: none; }
  #rolesPanel .panel-heading { margin-top: 0; }
  .role-vname { font-size: 48px; }
  .role-vname.is-long { font-size: 38px; }
  .role-quote { grid-area: quote; align-self: start; margin-top: 28px; font-size: 19px; -webkit-line-clamp: 6; line-clamp: 6; }
  .role-spread-meta { grid-area: meta; }
  .role-spread-actions { grid-area: actions; margin: 0; padding: 4px 0 0; background: none; }
  .role-spread-actions .select-role { flex: 1; }
}

@media (max-height: 780px) { #rolesPanel .panel-heading > p { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .role-spread.is-turning *, .role-seal.is-stamping { animation: none !important; }
}

/* Memory tab: "进入星图" on the memory page and "返回记忆" in the site header
   while the Beta full-screen star map is open. Both live outside the star map
   renderer; the header button uses the header's empty right side. */
.memory-universe-enter { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; margin: -4px 0 16px; padding: 0 16px 0 18px; border: 1px solid rgba(141, 38, 55, .18); border-radius: 999px; color: var(--accent); background: rgba(255, 255, 255, .7); font-size: 14px; font-weight: 600; }
.memory-universe-enter span { font-size: 18px; line-height: 1; }
.memory-universe-enter:hover { background: #fff; }
.memory-universe-enter:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.memory-universe-back { display: none; }
body[data-view^="memory-universe"] .memory-universe-back:not([hidden]) { display: inline-flex; flex: none; align-items: center; gap: 4px; min-height: 38px; padding: 0 16px 0 12px; border: 1px solid rgba(170, 183, 232, .22); border-radius: 999px; color: #eef2ff; background: rgba(6, 9, 22, .56); box-shadow: 0 12px 42px rgba(0, 0, 0, .38); font-size: 13px; }
body[data-view^="memory-universe"] .memory-universe-back span { font-size: 18px; line-height: 1; }
body[data-view^="memory-universe"] .memory-universe-back:focus-visible { outline: 2px solid #ffe8bd; outline-offset: 2px; }

.native-provider-settings{display:grid;gap:1rem}.native-provider-settings section{padding:1.2rem;border:1px solid #e5dce2;border-radius:1rem;display:grid;gap:.75rem}.native-provider-settings label{display:grid;gap:.35rem}.native-provider-settings input,.native-provider-settings select{max-width:100%;min-width:0;padding:.65rem;border:1px solid #ded4dc;border-radius:.6rem;background:#fff;color:inherit}.native-provider-settings button{margin:.25rem;padding:.65rem 1rem}.native-provider-settings p{overflow-wrap:anywhere}
