: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(1120px, calc(100% - 40px));
  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(1040px, calc(100% - 40px));
  margin: 28px auto 120px;
}

.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(3, 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;
}

.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; }
.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); }
.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-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 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.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); }
.role-voice-settings-card { width: min(560px, calc(100vw - 28px)); }
.role-voice-list { margin-top: 22px; }
.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; }
}

@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; }
}
