:root {
  color-scheme: dark;
  --bg: #0b0d11;
  --panel: #14171d;
  --panel-2: #191c23;
  --panel-3: #20242c;
  --line: rgba(255, 255, 255, .09);
  --line-strong: rgba(255, 255, 255, .15);
  --text: #f5f2ee;
  --muted: #9b9ca5;
  --muted-2: #6f727d;
  --accent: #d97998;
  --accent-2: #a88be6;
  --accent-soft: rgba(217, 121, 152, .14);
  --success: #67d3a2;
  --warning: #f0bb69;
  --danger: #ef7a86;
  --shadow: 0 30px 90px rgba(0, 0, 0, .48);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 4%, rgba(143, 102, 172, .17), transparent 28%),
    radial-gradient(circle at 96% 92%, rgba(174, 75, 108, .12), transparent 30%),
    var(--bg);
}
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }

.ambient { position: fixed; border-radius: 999px; filter: blur(100px); opacity: .12; pointer-events: none; }
.ambient-one { width: 420px; height: 420px; top: -230px; left: 30%; background: #a989ec; }
.ambient-two { width: 360px; height: 360px; right: -150px; bottom: -180px; background: #df6f94; }

.app-frame {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  width: min(1660px, calc(100vw - 32px));
  height: min(1040px, calc(100dvh - 32px));
  min-height: 0;
  margin: 16px auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(12, 14, 18, .86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.character-sidebar {
  z-index: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 22px 18px 18px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: rgba(21, 23, 29, .96);
}
.brand { display: flex; align-items: center; gap: 11px; width: max-content; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto;
  border-radius: 12px; background: linear-gradient(145deg, var(--accent), var(--accent-2));
  font-size: 12px; font-weight: 850; letter-spacing: .4px;
  box-shadow: 0 8px 25px rgba(202, 112, 155, .25);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .1px; }
.brand small { margin-top: 2px; color: var(--muted-2); font-size: 9px; letter-spacing: 1.4px; }

.sidebar-heading, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sidebar-heading { margin: 27px 2px 11px; color: #bfc0c7; font-size: 12px; font-weight: 700; }
.round-action {
  display: grid; place-items: center; width: 27px; height: 27px; border: 1px solid var(--line);
  border-radius: 9px; background: rgba(255,255,255,.035); color: #c7c6cd; font-size: 18px;
}
.round-action:hover { background: var(--accent-soft); border-color: rgba(217,121,152,.25); }

.character-list { display: flex; flex-direction: column; gap: 6px; max-height: 214px; min-height: 46px; overflow-y: auto; padding-right: 3px; }
.character-item {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  width: 100%; padding: 8px; border: 1px solid transparent; border-radius: 12px;
  background: transparent; text-align: left; cursor: pointer;
}
.character-item:hover { background: rgba(255,255,255,.04); }
.character-item.active { border-color: rgba(217,121,152,.22); background: var(--accent-soft); }
.mini-avatar, .header-avatar, .large-avatar, .empty-orbit span, .typing-avatar {
  display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, var(--character-accent, var(--accent)), #5a476f);
  font-family: Georgia, "Songti SC", serif;
}
.mini-avatar { width: 36px; height: 36px; border-radius: 12px; font-size: 15px; }
.character-item strong, .character-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.character-item strong { font-size: 12px; }
.character-item small { margin-top: 3px; color: var(--muted-2); font-size: 9px; }
.character-item .unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.character-item.disabled { opacity: .48; }

.active-card {
  position: relative; display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 12px;
  align-items: center; margin-top: 18px; padding: 16px 13px; border: 1px solid var(--line);
  border-radius: 16px; background: rgba(255,255,255,.035);
}
.large-avatar { width: 58px; height: 58px; border-radius: 20px; font-size: 23px; }
.active-card strong { display: block; font: 19px Georgia, "Songti SC", serif; }
.active-card p { display: -webkit-box; margin: 5px 0 0; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.5; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.relationship-pill { position: absolute; left: 13px; bottom: -9px; padding: 3px 8px; border: 1px solid rgba(217,121,152,.2); border-radius: 999px; background: #2a1e25; color: #f0afc3; font-size: 9px; }

.sidebar-controls { margin-top: 27px; }
.current-activity { display: flex; align-items: center; gap: 11px; margin-bottom: 11px; padding: 12px; border-radius: 13px; background: rgba(255,255,255,.035); }
.activity-icon { display: grid; place-items: center; width: 35px; height: 35px; border-radius: 11px; background: rgba(255,255,255,.06); }
.current-activity strong, .current-activity small { display: block; }
.current-activity strong { font-size: 12px; }
.current-activity small { margin-top: 3px; color: var(--muted); font-size: 9px; line-height: 1.4; }
.switch-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 2px; cursor: pointer; }
.switch-row strong, .switch-row small { display: block; }
.switch-row strong { font-size: 11px; font-weight: 650; }
.switch-row small { margin-top: 3px; color: var(--muted-2); font-size: 8px; }
.switch-row input { position: absolute; opacity: 0; }
.switch-row i { position: relative; width: 36px; height: 20px; flex: 0 0 auto; border-radius: 12px; background: #3a3d46; transition: .2s; }
.switch-row i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #aaaeb7; transition: .2s; }
.switch-row input:checked + i { background: rgba(217,121,152,.62); }
.switch-row input:checked + i::after { left: 19px; background: #fff0f5; }
.soft-button { width: 100%; margin-top: 9px; padding: 10px 12px; border: 1px solid rgba(217,121,152,.24); border-radius: 11px; background: var(--accent-soft); color: #efb1c5; font-size: 11px; cursor: pointer; }
.soft-button:hover { background: rgba(217,121,152,.21); }
.soft-button:disabled { opacity: .45; cursor: wait; }

.sidebar-footer { margin-top: auto; padding-top: 14px; }
.connection-card, .admin-link { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; }
.connection-card { padding: 12px 2px; border: 0; border-top: 1px solid var(--line); background: transparent; cursor: pointer; }
.connection-light { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--warning); box-shadow: 0 0 12px currentColor; }
.connection-card.online .connection-light { background: var(--success); }
.connection-card.error .connection-light { background: var(--danger); }
.connection-card strong, .connection-card small, .admin-link strong, .admin-link small { display: block; }
.connection-card strong, .admin-link strong { font-size: 10px; }
.connection-card small, .admin-link small { margin-top: 2px; color: var(--muted-2); font-size: 8px; }
.admin-link { padding: 10px; border-radius: 11px; background: rgba(255,255,255,.035); }
.admin-link > span:first-child { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; background: rgba(255,255,255,.05); }
.admin-link > span:nth-child(2) { flex: 1; min-width: 0; }
.admin-link b { color: var(--muted-2); font-weight: 400; }
.admin-link:hover { background: rgba(255,255,255,.065); }

.chat-panel { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: rgba(13, 15, 19, .84); }
.chat-header { display: flex; align-items: center; flex: 0 0 72px; min-width: 0; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--line); background: rgba(16,18,23,.86); }
.header-avatar { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 14px; font-size: 16px; }
.header-copy { min-width: 0; }
.header-copy strong, .header-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-copy strong { font: 17px Georgia, "Songti SC", serif; }
.header-copy span { margin-top: 4px; color: var(--muted); font-size: 10px; }
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.header-actions button, .labeled-action { height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.03); color: #b8bac2; font-size: 10px; cursor: pointer; }
.header-actions button:first-child { width: 34px; padding: 0; font-size: 18px; }
.header-actions button:hover, .labeled-action:hover { border-color: var(--line-strong); background: rgba(255,255,255,.065); color: #fff; }
.mobile-character-select { display: none; }


.message-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 24px clamp(24px, 6vw, 90px) 30px; overscroll-behavior: contain; scroll-behavior: smooth; }
.empty-state { display: flex; min-height: 100%; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-state.hidden { display: none; }
.empty-orbit { display: grid; place-items: center; width: 86px; height: 86px; border: 1px solid rgba(217,121,152,.18); border-radius: 50%; box-shadow: 0 0 0 14px rgba(217,121,152,.025), 0 0 0 28px rgba(217,121,152,.014); }
.empty-orbit span { width: 58px; height: 58px; border-radius: 20px; font-size: 22px; }
.empty-state h1 { margin: 34px 0 9px; font: 22px Georgia, "Songti SC", serif; }
.empty-state > p { max-width: 400px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.7; }
.quick-prompts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 22px; }
.quick-prompts button { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.03); color: #b0b0b8; font-size: 10px; cursor: pointer; }
.quick-prompts button:hover { border-color: rgba(217,121,152,.3); color: #fff; }

.message-row { display: flex; flex-direction: column; margin: 6px 0; animation: message-in .25s ease both; }
.message-row.user { align-items: flex-end; margin-top: 18px; }
.message-row.assistant { align-items: flex-start; }
.message-bubble { max-width: min(70%, 620px); padding: 11px 14px; border: 1px solid rgba(255,255,255,.045); border-radius: 8px 18px 18px 18px; background: #252830; color: #eeece9; font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-row.user .message-bubble { border-radius: 18px 8px 18px 18px; background: linear-gradient(135deg, var(--character-accent, var(--accent)), #865a84); color: #fff; }
.message-meta { display: flex; gap: 7px; align-items: center; margin: 4px 5px 0; color: #686a73; font-size: 8px; }
.message-source { color: #a27891; }
.date-divider { display: flex; align-items: center; gap: 13px; margin: 24px 0; color: #767781; font-size: 9px; }
.date-divider::before, .date-divider::after { content: ""; height: 1px; flex: 1; background: rgba(255,255,255,.05); }
@keyframes message-in { from { opacity: 0; transform: translateY(7px); } }

.typing-row { display: flex; align-items: center; flex: 0 0 auto; gap: 8px; padding: 0 clamp(24px, 6vw, 90px) 9px; color: var(--muted-2); font-size: 9px; }
.typing-row.hidden { visibility: hidden; height: 0; padding-bottom: 0; overflow: hidden; }
.typing-avatar { width: 25px; height: 25px; border-radius: 9px; font-size: 10px; }
.typing-bubble { display: flex; gap: 3px; padding: 8px 10px; border-radius: 7px 13px 13px 13px; background: #242730; }
.typing-bubble i { width: 4px; height: 4px; border-radius: 50%; background: #92939b; animation: typing 1.1s infinite; }
.typing-bubble i:nth-child(2) { animation-delay: .18s; }
.typing-bubble i:nth-child(3) { animation-delay: .36s; }
@keyframes typing { 0%, 65%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-3px); opacity: 1; } }

.composer-wrap { flex: 0 0 auto; padding: 12px clamp(22px, 5vw, 76px) 16px; border-top: 1px solid var(--line); background: rgba(15,17,22,.97); }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 7px 7px 7px 14px; border: 1px solid rgba(255,255,255,.12); border-radius: 17px; background: rgba(255,255,255,.035); transition: .2s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--character-accent, var(--accent)) 55%, transparent); box-shadow: 0 0 0 3px rgba(217,121,152,.06); }
.composer textarea { flex: 1; min-width: 0; min-height: 34px; max-height: 130px; padding: 7px 0; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; line-height: 1.5; }
.composer textarea::placeholder { color: #6e7079; }
.composer button { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border: 0; border-radius: 13px; background: linear-gradient(145deg, var(--character-accent, var(--accent)), #a2638d); color: #fff; font-size: 20px; cursor: pointer; }
.composer button:disabled { opacity: .45; cursor: wait; }
.composer-wrap > small { display: block; margin: 7px 5px 0; text-align: center; color: #62646d; font-size: 8px; }

.inspector-panel { position: absolute; z-index: 7; top: 0; right: 0; width: min(370px, calc(100% - 40px)); height: 100%; min-height: 0; padding: 22px; overflow-y: auto; border-left: 1px solid var(--line-strong); background: rgba(22,24,30,.985); box-shadow: -25px 0 70px rgba(0,0,0,.38); transform: translateX(103%); transition: transform .24s ease; }
.inspector-panel.open { transform: translateX(0); }
.inspector-panel > header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 23px; }
.inspector-panel > header small, .inspector-panel > header strong { display: block; }
.inspector-panel > header small { color: var(--accent-2); font-size: 8px; letter-spacing: 1.4px; }
.inspector-panel > header strong { margin-top: 5px; font: 21px Georgia,"Songti SC",serif; }
.inspector-panel > header button { border: 0; background: transparent; color: var(--muted); font-size: 25px; cursor: pointer; }
.inspector-panel section { padding: 0 0 21px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.inspector-panel section:last-child { border-bottom: 0; }
.section-heading { margin-bottom: 12px; }
.section-heading span { color: #c7c7cd; font-size: 11px; font-weight: 700; }
.section-heading small { color: var(--muted-2); font-size: 8px; }
.state-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.state-card { padding: 12px; border-radius: 12px; background: rgba(255,255,255,.04); }
.state-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.state-name { color: #b1b1b9; font-size: 9px; }
.state-value { font-size: 10px; font-variant-numeric: tabular-nums; }
.state-track { height: 4px; overflow: hidden; border-radius: 9px; background: rgba(255,255,255,.07); }
.state-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--accent-2),var(--character-accent,var(--accent))); transition: width .4s; }
.state-card.anger .state-fill { background: linear-gradient(90deg,#b3636e,var(--danger)); }
.state-card.energy .state-fill { background: linear-gradient(90deg,#6597b1,#78cfad); }
.memory-list { display: flex; flex-direction: column; gap: 8px; max-height: 390px; overflow-y: auto; }
.memory-empty { padding: 28px 16px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted-2); text-align: center; font-size: 9px; line-height: 1.7; }
.memory-item { position: relative; padding: 12px 11px 11px 16px; border-radius: 12px; background: rgba(255,255,255,.035); }
.memory-item::before { content: ""; position: absolute; left: 0; top: 14px; width: 3px; height: 19px; border-radius: 0 4px 4px 0; background: var(--accent-2); }
.memory-time { margin-bottom: 5px; color: var(--muted-2); font-size: 8px; }
.memory-summary { color: #cdccd1; font-size: 10px; line-height: 1.55; }
.memory-kind { display: inline-flex; margin-top: 8px; padding: 2px 6px; border-radius: 6px; background: rgba(168,139,230,.1); color: #aaa0c8; font-size: 7px; }
.debug-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.debug-buttons button { padding: 9px 7px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.03); color: #9b9da6; font-size: 9px; cursor: pointer; }
.debug-buttons button:hover { background: rgba(255,255,255,.065); color: #fff; }
.inspector-backdrop { position: absolute; z-index: 6; inset: 0; display: none; border: 0; background: rgba(5,6,9,.48); backdrop-filter: blur(2px); }
.inspector-backdrop.open { display: block; }

dialog { width: min(620px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line-strong); border-radius: 20px; color: var(--text); background: #191c22; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(4,5,7,.74); backdrop-filter: blur(8px); }
.model-form { padding: 26px; }
.model-form header { display: flex; justify-content: space-between; margin-bottom: 20px; }
.model-form header span { color: var(--accent); font-size: 8px; letter-spacing: 1.8px; }
.model-form h2 { margin: 5px 0 0; font: 22px Georgia,"Songti SC",serif; }
.dialog-close { border: 0; background: transparent; color: var(--muted); font-size: 27px; cursor: pointer; }
.dialog-note { margin: -5px 0 18px; padding: 11px 13px; border-radius: 10px; background: rgba(168,139,230,.07); color: #a3a0ac; font-size: 10px; line-height: 1.65; }
.model-form label { display: block; margin-bottom: 13px; color: #a8a7af; font-size: 10px; }
.model-form input { width: 100%; margin-top: 7px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; outline: 0; background: rgba(255,255,255,.035); color: var(--text); font-size: 11px; }
.model-form input:focus { border-color: rgba(217,121,152,.45); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.model-form footer { display: flex; justify-content: flex-end; gap: 9px; padding-top: 6px; }
.ghost-button, .primary-button { padding: 10px 18px; border-radius: 10px; font-size: 10px; cursor: pointer; }
.ghost-button { border: 1px solid var(--line); background: transparent; color: #a5a4ab; }
.primary-button { border: 0; background: linear-gradient(145deg,var(--accent),#9e658d); color: #fff; }

.toast-stack { position: fixed; z-index: 30; right: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 8px; }
.toast { max-width: 380px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 11px; background: #262a32; box-shadow: 0 12px 35px rgba(0,0,0,.38); color: #dedce1; font-size: 11px; animation: toast-in .22s ease; }
.toast.error { border-color: rgba(239,122,134,.32); }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.11); border-radius: 8px; }

@media (max-width: 1060px) {
  .app-frame { grid-template-columns: 250px minmax(0,1fr); }
  .character-sidebar { padding-left: 14px; padding-right: 14px; }
  .message-list { padding-left: 28px; padding-right: 28px; }
  .typing-row { padding-left: 28px; padding-right: 28px; }
  .composer-wrap { padding-left: 26px; padding-right: 26px; }
  .labeled-action:last-child { display: none; }
}

@media (max-width: 720px) {
  body { overflow: hidden; }
  .app-frame { grid-template-columns: 1fr; width: 100vw; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .character-sidebar { display: none; }
  .chat-header { flex-basis: 64px; padding: 0 12px; gap: 9px; }
  .mobile-character-select { display: block; width: 74px; padding: 7px 5px; border: 1px solid var(--line); border-radius: 9px; outline: 0; background: var(--panel-2); color: #d8d6db; font-size: 10px; }
  .header-avatar { width: 36px; height: 36px; border-radius: 12px; }
  .header-copy { flex: 1; }
  .header-actions { margin-left: 0; }
  .header-actions button:first-child, .header-actions .labeled-action:last-child { display: none; }
  .header-actions .labeled-action { width: auto; padding: 0 9px; font-size: 9px; }
  .message-list { padding: 17px 14px 22px; }
  .message-bubble { max-width: 86%; font-size: 13px; }
  .typing-row { padding-left: 14px; padding-right: 14px; }
  .composer-wrap { padding: 9px 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer-wrap > small { display: none; }
  .inspector-panel { position: fixed; width: min(370px, 92vw); border-radius: 18px 0 0 18px; }
  .inspector-backdrop { position: fixed; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .toast-stack { right: 12px; bottom: 12px; left: 12px; }
  .toast { max-width: none; }
}
