:root {
    --bg: #0b0d12;
    --panel: #11141b;
    --panel-2: #171b24;
    --line: rgba(255, 255, 255, .09);
    --line-2: rgba(255, 255, 255, .15);
    --text: #f6f7fb;
    --text-2: #c8ceda;
    --muted: #858d9d;
    --accent: #10a37f;
    --danger: #ef4444;
    --radius: 18px;
}

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

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
}

body,
input,
textarea,
select,
button {
    font-family: inherit;
}

body {
    user-select: text;
    -webkit-user-select: text;
}

button {
    border: 0;
}

.app-shell {
    min-height: 100vh;
    background: var(--bg);
}

.view {
    min-height: 100vh;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
}

.app-mobile {
    width: min(100%, 520px);
    margin: 0 auto;
}

.mobile-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -14px -14px 14px;
    padding: calc(14px + env(safe-area-inset-top)) 14px 12px;
    background: rgba(11, 13, 18, .92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(18px);
}

.mobile-title {
    min-width: 0;
}

.mobile-title h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
    font-weight: 780;
}

.mobile-title p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.icon-btn,
.primary-btn,
.ghost-btn,
.danger-btn,
.send-btn {
    min-height: 42px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform .12s ease, background .16s ease, border-color .16s ease;
}

.icon-btn {
    width: 42px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
}

.primary-btn,
.ghost-btn,
.danger-btn {
    gap: 7px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 700;
}

.primary-btn {
    color: #0b0d12;
    background: #f7f8fb;
}

.ghost-btn {
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
}

.danger-btn {
    color: #fecaca;
    background: rgba(239, 68, 68, .12);
    border: 1px solid rgba(239, 68, 68, .26);
}

.send-btn {
    width: 46px;
    height: 46px;
    color: #0b0d12;
    background: #f7f8fb;
    border-radius: 50%;
}

.icon-btn:active,
.primary-btn:active,
.ghost-btn:active,
.danger-btn:active,
.send-btn:active {
    transform: scale(.96);
}

button[disabled] {
    opacity: .55;
    pointer-events: none;
}

.mui-icon {
    font-size: 21px;
}

.search-box {
    position: relative;
    margin-bottom: 14px;
}

.search-box .mui-icon {
    position: absolute;
    top: 50%;
    left: 14px;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 19px;
}

.search-input,
.input,
.textarea,
.select {
    width: 100%;
    margin: 0;
    border: 1px solid var(--line) !important;
    border-radius: 16px !important;
    outline: none;
    background: var(--panel) !important;
    color: var(--text) !important;
    user-select: text;
    -webkit-user-select: text;
    appearance: none;
    -webkit-appearance: none;
}

.search-input {
    height: 48px;
    padding: 0 14px 0 44px !important;
}

.input,
.select {
    min-height: 46px;
    padding: 0 13px !important;
}

.textarea {
    min-height: 104px;
    padding: 12px 13px !important;
    line-height: 1.6;
    resize: vertical;
}

.character-list {
    display: grid;
    gap: 10px;
}

.character-card {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.character-main {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 12px;
}

.avatar {
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 50%;
    color: var(--text);
    background: #232936;
    border: 1px solid var(--line-2);
    font-size: 18px;
    font-weight: 800;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-copy {
    min-width: 0;
}

.character-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.character-card h2 {
    overflow: hidden;
    margin: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 17px;
    line-height: 1.25;
}

.character-card p {
    margin: 6px 0 10px;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.55;
}

.badge,
.tag {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    white-space: nowrap;
}

.badge {
    height: 24px;
    padding: 0 8px;
    color: var(--muted);
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--line);
    font-size: 12px;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    padding: 4px 8px;
    color: var(--muted);
    background: rgba(255, 255, 255, .05);
    font-size: 12px;
}

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-left: 60px;
}

.panel {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.stack {
    display: grid;
    gap: 14px;
}

.field {
    display: grid;
    gap: 8px;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.secret-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px;
    gap: 8px;
}

.status-box,
.info-list {
    padding: 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .04);
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
}

.model-tools {
    display: grid;
    gap: 8px;
}

.model-tool-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.model-list {
    display: grid;
    gap: 8px;
}

.model-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, .035);
}

.model-row.active {
    border-color: rgba(16, 163, 127, .55);
    background: rgba(16, 163, 127, .12);
}

.model-row span {
    overflow: hidden;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-row span em {
    display: inline-flex;
    margin-left: 8px;
    padding: 2px 6px;
    border-radius: 999px;
    color: #b7f7e7;
    background: rgba(16, 163, 127, .18);
    font-size: 11px;
    font-style: normal;
    vertical-align: middle;
}

.model-actions {
    display: flex;
    gap: 6px;
}

.mini-btn {
    min-width: 34px;
    height: 32px;
    border-radius: 10px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    font-size: 12px;
}

.danger-mini {
    color: #fecaca;
    background: rgba(239, 68, 68, .12);
    border-color: rgba(239, 68, 68, .26);
}

.steps {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.step-dot {
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .1);
}

.step-dot.active {
    background: #f7f8fb;
}

.form-nav {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.empty {
    padding: 28px 16px;
    border: 1px dashed var(--line-2);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
    background: rgba(255, 255, 255, .025);
}

.chat-view {
    height: 100vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: var(--bg);
}

.chat-header {
    z-index: 20;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    align-items: center;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    border-bottom: 1px solid var(--line);
    background: rgba(11, 13, 18, .94);
    backdrop-filter: blur(18px);
}

.chat-identity {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
}

.chat-identity .avatar {
    width: 34px;
    height: 34px;
    font-size: 14px;
}

.chat-identity h1 {
    overflow: hidden;
    margin: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
}

.chat-identity p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 11px;
}

.messages {
    overflow-y: auto;
    padding: 16px 12px 96px;
}

.message {
    display: flex;
    margin-bottom: 12px;
}

.message.user {
    justify-content: flex-end;
}

.bubble {
    max-width: 88%;
    padding: 12px 13px;
    border-radius: 18px;
    color: var(--text);
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14px;
}

.message.user .bubble {
    background: #2a303c;
    border-bottom-right-radius: 6px;
}

.message.assistant .bubble {
    background: var(--panel);
    border: 1px solid var(--line);
    border-bottom-left-radius: 6px;
}

.rp-memory {
    color: var(--muted);
    font-size: 12px;
}

.rp-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0;
}

.rp-meta span {
    padding: 4px 7px;
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255, 255, 255, .05);
    font-size: 12px;
}

.rp-mind {
    margin: 8px 0;
    padding: 9px 10px;
    border-left: 2px solid var(--line-2);
    color: var(--text-2);
    background: rgba(255, 255, 255, .035);
    font-style: italic;
}

.rp-dialog {
    color: var(--text);
}

.composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 22;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 46px;
    gap: 8px;
    width: min(100%, 520px);
    margin: 0 auto;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(11, 13, 18, .96);
    border-top: 1px solid var(--line);
}

.composer .textarea {
    min-height: 46px;
    max-height: 120px;
    resize: none;
}

.drawer-mask {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: none;
    background: rgba(0, 0, 0, .55);
}

.drawer-mask.open {
    display: block;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 31;
    width: min(92vw, 380px);
    padding: calc(14px + env(safe-area-inset-top)) 14px 16px;
    overflow-y: auto;
    background: #0f1218;
    border-left: 1px solid var(--line);
    transform: translateX(100%);
    transition: transform .2s ease;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.drawer h2 {
    margin: 0 0 10px;
    font-size: 18px;
}

.memory-item {
    margin-bottom: 8px;
    padding: 10px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .04);
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.55;
}

.relation-card {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .04);
    border: 1px solid var(--line);
}

.relation-stage {
    display: grid;
    gap: 4px;
}

.relation-stage span {
    font-size: 15px;
    font-weight: 800;
}

.relation-stage small {
    color: var(--muted);
    line-height: 1.45;
}

.relation-line {
    display: flex;
    justify-content: space-between;
    color: var(--text-2);
    font-size: 12px;
}

.relation-line b {
    color: var(--text);
    font-weight: 700;
}

.meter-track {
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, .08);
}

.meter-track i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.meter-track i.warn {
    background: var(--danger);
}

.typing {
    display: inline-flex;
    gap: 5px;
}

.typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: blink 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
    animation-delay: .15s;
}

.typing span:nth-child(3) {
    animation-delay: .3s;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(22px + env(safe-area-inset-bottom));
    z-index: 100;
    max-width: min(90vw, 420px);
    padding: 10px 14px;
    border-radius: 14px;
    color: var(--text);
    background: #202633;
    border: 1px solid var(--line-2);
    opacity: 0;
    transform: translate(-50%, 10px);
    pointer-events: none;
    transition: opacity .16s ease, transform .16s ease;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (min-width: 760px) {
    .app-mobile {
        padding-top: 10px;
    }

    .character-card {
        transition: transform .16s ease, border-color .16s ease, background .16s ease;
    }

    .character-card:hover {
        transform: translateY(-2px);
        border-color: var(--line-2);
        background: var(--panel-2);
    }
}

@keyframes blink {
    0%, 80%, 100% {
        opacity: .35;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}
