:root {
    --bg-primary: #080a0f;
    --bg-secondary: rgba(13, 16, 24, 0.9);
    --bg-tertiary: rgba(24, 28, 40, 0.84);
    --text-primary: #f7f7fb;
    --text-secondary: #a2a8bd;
    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --accent-subtle: rgba(139, 92, 246, 0.14);
    --success: #34d399;
    --danger: #fb7185;
    --error: var(--danger);
    --warning: #f59e0b;
    --border: rgba(255, 255, 255, 0.11);
    --border-subtle: rgba(255, 255, 255, 0.07);
    --user-bg: rgba(14, 116, 144, 0.14);
    --ai-bg: rgba(139, 92, 246, 0.13);
    --shadow: 0 18px 55px rgba(0, 0, 0, 0.38);
    --radius: 8px;
    --kiki-cyan: #22d3ee;
    --kiki-amber: #f59e0b;
    --kiki-rose: #fb7185;
}

html {
    background: #080a0f;
    color-scheme: dark;
}

body {
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(135deg, #080a0f 0%, #10131c 34%, #17121e 66%, #071716 100%);
}

select,
select option,
select optgroup {
    color-scheme: dark;
    background-color: #0d1018;
    color: var(--text-primary);
}

select option:checked,
select option:hover,
select option:focus {
    background-color: #1f2636;
    color: #ffffff;
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
}

body::before {
    z-index: 0;
    opacity: 0.18;
    background:
        linear-gradient(115deg, rgba(34, 211, 238, 0.2), transparent 28%, rgba(245, 158, 11, 0.12) 58%, transparent 78%),
        url("/static/img/kiki-bg.png") center / cover no-repeat;
    filter: saturate(1.1) contrast(1.05);
}

body::after {
    z-index: 0;
    opacity: 0.22;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 74px 74px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.78), transparent 76%);
}

.app-container {
    position: relative;
    z-index: 1;
    isolation: isolate;
}

.sidebar,
.chat-header,
.input-container,
.modal,
.character-panel,
.world-info-panel,
.header-dropdown-menu,
.emote-picker,
.emote-autocomplete,
.emoji-picker {
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
}

.sidebar {
    width: 300px;
    min-width: 300px;
    background: rgba(10, 13, 20, 0.9);
    border-right: 1px solid var(--border);
    box-shadow: 18px 0 48px rgba(0, 0, 0, 0.26);
    position: relative;
}

.sidebar::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--kiki-cyan), var(--kiki-amber));
    opacity: 0.78;
}

.sidebar-header {
    padding: 18px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent);
    border-bottom: 1px solid var(--border-subtle);
}

.logo {
    display: flex;
    align-items: center;
    color: var(--text-primary);
    background: none;
    -webkit-text-fill-color: currentColor;
    letter-spacing: 0;
    font-size: 19px;
    gap: 2px;
}

.logo img {
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12), 0 12px 26px rgba(0, 0, 0, 0.34);
}

.sidebar-tabs {
    margin: 0 12px 10px;
    padding: 4px;
    gap: 4px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.045);
}

.sidebar-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    border: 0;
    border-radius: 6px;
    color: var(--text-secondary);
    letter-spacing: 0;
}

.sidebar-tab.active {
    color: #fff;
    border-bottom-color: transparent;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.9), rgba(8, 145, 178, 0.86));
    box-shadow: 0 10px 28px rgba(8, 145, 178, 0.18);
}

.sidebar-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.sidebar-tab.active:hover {
    color: #fff;
}

.sidebar-content {
    padding: 6px 0 10px;
}

.folder-filter {
    padding: 8px 12px 12px;
    border-bottom: 0;
}

.folder-chip {
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.045);
}

.folder-chip.active {
    background: linear-gradient(135deg, var(--accent), #0891b2);
    border-color: transparent;
}

.chat-list {
    padding: 0 0 8px;
}

.chat-item {
    margin: 0 10px 8px;
    padding: 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.035);
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.chat-item::before {
    content: "";
    position: absolute;
    left: 0;
    top: 11px;
    bottom: 11px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: transparent;
}

.chat-item:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.065);
    border-color: rgba(255, 255, 255, 0.1);
}

.chat-item.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.18), rgba(34, 211, 238, 0.1));
    border-color: rgba(139, 92, 246, 0.34);
    box-shadow: 0 10px 30px rgba(139, 92, 246, 0.12);
}

.chat-item.active::before {
    background: linear-gradient(180deg, var(--accent), var(--kiki-cyan));
}

.chat-item-avatar {
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(34, 211, 238, 0.18));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.chat-item-name {
    color: var(--text-primary);
    font-weight: 650;
}

.chat-item-preview {
    color: rgba(220, 226, 240, 0.62);
}

.sidebar-footer {
    padding: 14px;
    background: rgba(8, 10, 15, 0.56);
    border-top: 1px solid var(--border-subtle);
}

.btn,
.form-input,
.form-control,
.tool-btn,
.send-btn,
.swipe-btn,
.action-btn {
    border-radius: 8px;
}

.btn {
    letter-spacing: 0;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #0891b2);
    box-shadow: 0 10px 30px rgba(8, 145, 178, 0.22);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-hover), var(--kiki-cyan));
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.055);
    border-color: var(--border-subtle);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.085);
    border-color: rgba(139, 92, 246, 0.36);
}

.main-area {
    position: relative;
    background: transparent;
    min-height: 0;
}

.chat-header {
    min-height: 70px;
    padding: 12px 22px;
    background: rgba(8, 10, 15, 0.74);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
    z-index: 40;
}

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

.character-avatar {
    width: 50px;
    height: 50px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12), 0 16px 34px rgba(0, 0, 0, 0.35);
}

.character-avatar img {
    width: 100% !important;
    height: 100% !important;
}

.character-name {
    font-size: 18px;
    color: var(--text-primary);
}

.character-status {
    gap: 8px;
    flex-wrap: wrap;
}

.mood-indicator {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.055);
    color: var(--text-primary);
}

.header-dropdown-menu {
    background: rgba(12, 15, 23, 0.94);
    border-color: var(--border);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.header-dropdown-menu button {
    border-radius: 6px;
}

.header-dropdown-menu button:hover {
    background: rgba(139, 92, 246, 0.13);
}

.messages-container {
    padding: 24px 22px 20px;
    gap: 12px;
    min-height: 0;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 18%),
        linear-gradient(135deg, rgba(34, 211, 238, 0.05), transparent 35%, rgba(245, 158, 11, 0.045) 100%);
}

.messages-container.show-bg {
    background:
        linear-gradient(180deg, rgba(8, 10, 15, 0.38), rgba(8, 10, 15, 0.82)),
        url("/static/img/kiki-bg.png") center / cover no-repeat;
}

.messages-container.show-bg::before {
    background:
        linear-gradient(135deg, rgba(8, 10, 15, 0.48), rgba(8, 10, 15, 0.76)),
        linear-gradient(90deg, rgba(34, 211, 238, 0.12), transparent 44%, rgba(245, 158, 11, 0.1));
}

.message,
.message-load-more,
.message-window-notice,
.typing-indicator,
.onboarding-state {
    position: relative;
    z-index: 1;
}

.message {
    width: min(100%, 980px);
    margin: 0 auto;
    padding: 15px 16px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: rgba(13, 16, 24, 0.64);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
    overflow: visible;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.message::before {
    content: "";
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: rgba(255, 255, 255, 0.12);
}

.message-ai {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.14), rgba(13, 16, 24, 0.72));
    border-color: rgba(139, 92, 246, 0.18);
}

.message-ai::before {
    background: linear-gradient(180deg, var(--accent), var(--kiki-cyan));
}

.message-user {
    background: linear-gradient(135deg, rgba(8, 145, 178, 0.14), rgba(13, 16, 24, 0.72));
    border-color: rgba(34, 211, 238, 0.16);
}

.message-user::before {
    background: linear-gradient(180deg, var(--kiki-cyan), var(--success));
}

.message:hover,
.message-user:hover,
.message-ai:hover {
    transform: translateY(-1px);
    background-color: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.16);
}

.message-system {
    margin: 0 auto;
    border: 1px solid rgba(245, 158, 11, 0.22);
    background: rgba(245, 158, 11, 0.08);
    color: #fde68a;
}

.message-header {
    margin-bottom: 9px;
}

.message-avatar {
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.035);
}

.message-ai .message-avatar {
    border-color: rgba(139, 92, 246, 0.46);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12), 0 12px 26px rgba(0, 0, 0, 0.22);
}

.message-user .message-avatar {
    border-color: rgba(34, 211, 238, 0.42);
    box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.1), 0 12px 26px rgba(0, 0, 0, 0.22);
}

.message-name {
    color: var(--kiki-cyan);
    letter-spacing: 0;
}

.message-user .message-name {
    color: #67e8f9;
}

.message-source,
.context-chip,
.reaction-badge {
    background: rgba(255, 255, 255, 0.055);
    border-color: var(--border-subtle);
}

.message-body {
    padding-left: 52px;
    line-height: 1.72;
}

.message-content {
    max-width: none;
}

.message-content .dialogue {
    color: #fcd34d;
}

.message-content .action,
.message-content em {
    color: #c4b5fd;
}

.message-actions {
    right: 12px;
    top: 12px;
    padding: 4px;
    border-radius: 8px;
    background: rgba(8, 10, 15, 0.86);
    border-color: var(--border-subtle);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
}

.action-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: rgba(139, 92, 246, 0.18);
}

.message-image {
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.3);
}

.typing-indicator {
    width: min(100%, 980px);
    margin: 0 auto 12px;
    border: 1px solid rgba(139, 92, 246, 0.18);
    border-radius: 8px;
    background: rgba(139, 92, 246, 0.1);
}

.input-area {
    padding: 12px 24px 18px;
    background: linear-gradient(to top, rgba(8, 10, 15, 0.98), rgba(8, 10, 15, 0.82), transparent);
    z-index: 35;
}

.input-container {
    width: min(1100px, 100%);
    margin: 0 auto;
    padding: 8px 10px 8px 12px;
    background: rgba(12, 15, 23, 0.9);
    border-color: rgba(255, 255, 255, 0.14);
    box-shadow: 0 -12px 45px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.input-wrapper {
    gap: 8px;
}

.input-tools,
.composer-quick-actions {
    gap: 6px;
}

.tool-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.055);
    border: 1px solid transparent;
}

.tool-btn:hover {
    color: #fff;
    background: rgba(139, 92, 246, 0.16);
    border-color: rgba(139, 92, 246, 0.28);
}

.tool-btn.active {
    background: linear-gradient(135deg, var(--accent), #0891b2);
    border-color: transparent;
}

#messageInput {
    min-height: 36px;
    line-height: 1.5;
    padding: 2px 0;
}

.send-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), #0891b2);
    box-shadow: 0 12px 28px rgba(8, 145, 178, 0.28);
}

.send-btn:hover {
    background: linear-gradient(135deg, var(--accent-hover), var(--kiki-cyan));
    transform: translateY(-1px);
}

.send-btn:disabled {
    background: rgba(255, 255, 255, 0.08);
}

.context-bar {
    margin-top: 4px;
    padding: 7px 9px;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
}

.context-bar progress::-webkit-progress-bar {
    background: rgba(255, 255, 255, 0.08);
}

.context-bar progress::-webkit-progress-value {
    background: linear-gradient(90deg, var(--kiki-cyan), var(--accent));
}

.onboarding-state {
    width: min(920px, calc(100% - 32px));
    min-height: min(640px, calc(100% - 32px));
    max-height: calc(100% - 32px);
    height: auto;
    margin: auto;
    align-items: stretch;
    justify-content: flex-start;
    text-align: left;
    padding: 36px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    background:
        linear-gradient(135deg, rgba(13, 16, 24, 0.78), rgba(9, 20, 24, 0.72)),
        url("/static/img/kiki-bg.png") center / cover no-repeat;
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.messages-container.show-bg .onboarding-state {
    width: min(920px, calc(100% - 32px));
    max-width: 920px;
    padding: 36px;
    border-radius: 8px;
}

.onboarding-state::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 22%, rgba(255, 255, 255, 0.08) 46%, transparent 64%);
    transform: translateX(-100%);
    animation: kikiPanelSheen 8s ease-in-out infinite;
    pointer-events: none;
}

@keyframes kikiPanelSheen {
    0%, 52% { transform: translateX(-100%); }
    72%, 100% { transform: translateX(100%); }
}

.onboarding-icon,
.onboarding-title,
.onboarding-sub,
.onboarding-steps,
.starter-kit-section {
    position: relative;
    z-index: 1;
}

.onboarding-icon {
    justify-content: flex-start;
}

.onboarding-icon img {
    width: 108px;
    height: 108px;
    opacity: 1;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 0 6px rgba(139, 92, 246, 0.14), 0 18px 46px rgba(0, 0, 0, 0.42);
}

.onboarding-title {
    font-size: 30px;
    font-weight: 750;
}

.onboarding-sub {
    max-width: 520px;
    color: rgba(241, 245, 249, 0.78);
}

.onboarding-steps {
    justify-content: flex-start;
}

.onboarding-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
    position: relative;
    z-index: 1;
}

.onboarding-step,
.starter-kit-card,
.gallery-card,
.context-inspector-stat,
.context-inspector-section,
.context-inspector-item,
.quality-feedback-option,
.greeting-choice,
.memory-fact-item,
.ob-feature,
.ob-char-type {
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.055);
    border-color: var(--border-subtle);
}

.onboarding-step:hover,
.starter-kit-card:hover,
.gallery-card:hover {
    border-color: rgba(34, 211, 238, 0.28);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.25);
}

.onboarding-step-num {
    background: linear-gradient(135deg, var(--accent), #0891b2);
}

.starter-kit-heading {
    justify-content: flex-start;
    color: #dbeafe;
}

.starter-kit-card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035));
}

.ob-overlay {
    overflow-y: auto;
}

.ob-card {
    max-height: min(760px, calc(100dvh - 32px));
    overflow-y: auto;
    border-radius: 8px;
    scrollbar-gutter: stable;
}

.ob-footer {
    position: relative;
    z-index: 3;
    padding-top: 12px;
    background: transparent;
}

.starter-kit-tagline {
    color: var(--kiki-cyan);
}

.gallery-card-avatar {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.82), rgba(8, 145, 178, 0.82));
}

.modal-overlay {
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
}

.modal,
.character-panel,
.world-info-panel {
    background: rgba(12, 15, 23, 0.94);
    border-color: var(--border);
    box-shadow: var(--shadow);
}

.modal-header,
.panel-header {
    border-bottom: 1px solid var(--border-subtle);
}

.form-input,
.form-control,
.emote-picker-header input,
#searchInput,
textarea {
    background: rgba(255, 255, 255, 0.055);
    border-color: var(--border-subtle);
}

.form-input:focus,
.form-control:focus,
.emote-picker-header input:focus,
#searchInput:focus {
    border-color: rgba(34, 211, 238, 0.46);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

::-webkit-scrollbar {
    width: 7px;
}

::-webkit-scrollbar-thumb {
    background: rgba(162, 168, 189, 0.32);
}

.is-mobile-layout body,
.is-mobile-layout body.chat-page {
    overflow-x: hidden;
}

.is-mobile-layout .app-container,
.is-mobile-layout .main-area,
.is-mobile-layout .chat-header,
.is-mobile-layout .messages-container,
.is-mobile-layout .input-area,
.is-mobile-layout .chat-input-area {
    max-width: 100vw;
    min-width: 0;
    overflow-x: hidden;
}

.is-mobile-layout .messages-container {
    width: 100%;
    padding-left: clamp(8px, 3vw, 14px);
    padding-right: clamp(8px, 3vw, 14px);
}

.is-mobile-layout .message,
.is-mobile-layout .message-load-more,
.is-mobile-layout .message-window-notice,
.is-mobile-layout .typing-indicator {
    width: 100%;
    max-width: calc(100vw - 20px);
    min-width: 0;
}

.is-mobile-layout .message-body,
.is-mobile-layout .message-content,
.is-mobile-layout .message-header,
.is-mobile-layout .input-container,
.is-mobile-layout .input-wrapper {
    min-width: 0;
    max-width: 100%;
}

.is-mobile-layout .message-content,
.is-mobile-layout .message-content * {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.is-mobile-layout .input-area {
    box-sizing: border-box;
    width: 100%;
    padding-left: 10px;
    padding-right: 10px;
}

.is-mobile-layout #messageInput {
    min-width: 0;
    max-width: 100%;
}

.is-mobile-layout .context-bar {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.is-mobile-layout .context-insights.active {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.is-mobile-layout .context-insights.active::-webkit-scrollbar {
    display: none;
}

.is-mobile-layout .context-chip {
    flex: 0 0 auto;
    max-width: min(280px, calc(100vw - 40px));
    min-width: 0;
}

.is-mobile-layout .context-chip strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.is-smartphone body {
    overflow: hidden;
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

.is-smartphone .app-container {
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
}

.is-smartphone .main-area {
    width: 100%;
    min-width: 0;
}

.is-smartphone .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 10px 12px;
}

.is-smartphone .mobile-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    font-size: 22px;
}

.is-smartphone .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: calc(60px + env(safe-area-inset-bottom));
    width: min(88vw, 330px);
    min-width: 0;
    z-index: 1001;
    transition: left 0.28s cubic-bezier(.4, 0, .2, 1);
    background: rgba(10, 13, 20, 0.97);
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.5);
}

.is-smartphone .sidebar.open {
    left: 0;
}

.is-smartphone .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
}

.is-smartphone .sidebar-tabs {
    display: flex;
    flex-shrink: 0;
    margin: 0 10px 8px;
}

.is-smartphone .sidebar-tab {
    flex-direction: column;
    gap: 3px;
    min-height: 42px;
    padding: 6px 4px;
    font-size: 11px;
}

.is-smartphone .sidebar-content {
    -webkit-overflow-scrolling: touch;
}

.is-smartphone .sidebar-footer {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.is-smartphone .sidebar-overlay {
    position: fixed;
    inset: 0 0 calc(60px + env(safe-area-inset-bottom)) 0;
    z-index: 1000;
    display: none;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.is-smartphone .sidebar-overlay.active {
    display: block;
}

.is-smartphone .chat-header {
    min-height: 64px;
    padding: 10px 12px;
    overflow: visible;
}

.is-smartphone .character-info {
    min-width: 0;
    gap: 10px;
}

.is-smartphone .character-name {
    max-width: 44vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
}

.is-smartphone .character-status {
    gap: 6px;
}

.is-smartphone .mood-indicator {
    padding: 6px 10px;
    font-size: 13px;
}

.is-smartphone .header-actions,
.is-smartphone .header-dropdown {
    overflow: visible;
}

.is-smartphone .header-dropdown-menu {
    position: fixed !important;
    top: auto !important;
    bottom: -100% !important;
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    max-height: 85dvh;
    border-radius: 20px 20px 0 0;
    background: var(--bg-secondary);
    box-shadow: 0 -10px 40px rgba(0,0,0,0.6);
    z-index: 10000;
    transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), visibility 0.3s;
    display: flex;
    flex-direction: column;
    padding: 24px 0 env(safe-area-inset-bottom);
    border: 1px solid var(--border);
    border-bottom: none;
    overflow-y: auto;
    visibility: hidden;
}

.is-smartphone .header-dropdown-menu::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
}

.is-smartphone .header-dropdown-menu.open {
    bottom: 0 !important;
    visibility: visible !important;
}

.is-smartphone .messages-container {
    padding: 16px 10px calc(var(--kiki-input-area-height, 120px) + 60px + env(safe-area-inset-bottom));
    gap: 10px;
}

.is-smartphone .message {
    width: 100%;
    max-width: 100%;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 14px;
}

.is-smartphone .message-body {
    padding-left: 42px;
}

.is-smartphone .message-actions {
    display: flex;
    position: static;
    flex-wrap: wrap;
    margin-top: 10px;
    padding: 0;
    border: none;
    background: transparent;
}

.is-smartphone .input-area {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(60px + env(safe-area-inset-bottom));
    z-index: 180;
    padding: 8px 10px 10px;
}

.is-smartphone .input-container {
    padding: 8px 10px;
    gap: 8px;
    border-radius: 8px;
}

.is-smartphone .input-tools,
.is-smartphone .composer-quick-actions {
    display: flex;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.is-smartphone .input-tools::-webkit-scrollbar,
.is-smartphone .composer-quick-actions::-webkit-scrollbar {
    display: none;
}

.is-smartphone .tool-btn {
    min-width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.is-smartphone .send-btn {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
}

.is-smartphone #messageInput {
    font-size: 16px;
    line-height: 1.4;
}

.is-smartphone .context-bar {
    display: none;
}

.is-smartphone .mobile-nav {
    display: flex;
}

.is-smartphone .scroll-bottom-btn {
    bottom: calc(var(--kiki-input-area-height, 120px) + 60px + env(safe-area-inset-bottom));
}

.is-smartphone .onboarding-state {
    width: 100%;
    min-height: auto;
    max-height: calc(100dvh - 370px);
    justify-content: flex-start;
    gap: 8px;
    padding: 14px;
    margin: 0 auto 18px;
    overflow-y: auto;
}

.is-smartphone .messages-container.show-bg .onboarding-state {
    width: 100%;
    max-width: none;
    padding: 14px;
}

.is-smartphone .onboarding-icon {
    justify-content: center;
}

.is-smartphone .onboarding-icon img {
    width: 56px;
    height: 56px;
    margin-bottom: 0;
}

.is-smartphone .onboarding-title,
.is-smartphone .onboarding-sub {
    text-align: center;
}

.is-smartphone .onboarding-title {
    font-size: 22px;
}

.is-smartphone .onboarding-sub {
    font-size: 13px;
    line-height: 1.35;
}

.is-smartphone .onboarding-steps,
.is-smartphone .starter-kit-heading {
    justify-content: center;
}

.is-smartphone .onboarding-steps {
    gap: 8px;
}

.is-smartphone .onboarding-step {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: none;
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 8px 10px;
    text-align: left;
}

.is-smartphone .onboarding-step-num {
    width: 26px;
    height: 26px;
    margin: 0;
    flex: 0 0 26px;
}

.is-smartphone .onboarding-step-text {
    font-size: 12px;
}

.is-smartphone .onboarding-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 0;
}

.is-smartphone .onboarding-actions .btn {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
}

.is-smartphone .starter-kit-section {
    display: block;
    max-width: none;
    margin-top: 2px;
}

.is-smartphone .starter-kit-heading {
    margin-bottom: 8px;
    font-size: 11px;
}

.is-smartphone .starter-kit-grid {
    grid-template-columns: 1fr;
    gap: 8px;
}

.is-smartphone .starter-kit-card {
    min-height: 0;
    padding: 11px;
}

.is-smartphone .starter-kit-description {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.is-smartphone .modal-overlay {
    align-items: flex-end;
    padding: 0;
}

.is-smartphone .modal {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: none;
}

.is-smartphone .character-panel,
.is-smartphone .world-info-panel {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: -100%;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 75vh;
    z-index: 1002;
    overflow-y: auto;
    border-radius: 8px 8px 0 0;
    border: none;
    border-top: 1px solid var(--border);
    transition: bottom 0.3s cubic-bezier(.4, 0, .2, 1);
    -webkit-overflow-scrolling: touch;
}

.is-smartphone .character-panel.open,
.is-smartphone .world-info-panel.open {
    bottom: calc(60px + env(safe-area-inset-bottom));
}

.is-smartphone .panel-overlay {
    position: fixed;
    inset: 0 0 calc(60px + env(safe-area-inset-bottom)) 0;
    display: none;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.is-smartphone .panel-overlay.active {
    display: block;
}

.is-smartphone .ob-overlay {
    align-items: flex-start;
    padding: 12px;
}

.is-smartphone .ob-card {
    max-height: calc(100dvh - 24px);
    padding: 22px 16px 16px;
    border-radius: 8px;
}

.is-smartphone .ob-char-types,
.is-smartphone .ob-starter-kits {
    grid-template-columns: 1fr;
    gap: 8px;
}

/* Migrated from inline @media (max-width: 768px) in chat.html */
.is-smartphone .logo { font-size: 20px; }

.is-smartphone .message-content {
    font-size: 15px;
    line-height: 1.6;
}

.is-smartphone .chat-input-area {
    position: fixed;
    bottom: calc(60px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 110;
}

.is-smartphone .input-actions {
    gap: 8px;
    flex-wrap: nowrap;
}

.is-smartphone .input-actions .btn {
    padding: 10px 16px;
    font-size: 15px;
    white-space: nowrap;
}

.is-smartphone .mood-emoji { font-size: 16px; }

.is-smartphone .character-status {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.is-smartphone .modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10;
}

.is-smartphone .modal-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
}

.is-smartphone .modal-title {
    font-size: 18px;
    margin-top: 12px;
}

.is-smartphone .modal-close {
    width: 36px;
    height: 36px;
    font-size: 20px;
}

.is-smartphone .btn {
    padding: 12px 20px;
    font-size: 15px;
    min-height: 48px;
}

.is-smartphone .btn-icon {
    min-width: 44px;
    min-height: 44px;
}

.is-smartphone .import-area {
    padding: 24px 16px;
    border-radius: 12px;
}

.is-smartphone .import-area i { font-size: 36px; }
.is-smartphone .import-area strong { font-size: 16px; }

.is-smartphone .form-group { margin-bottom: 16px; }
.is-smartphone .form-group label { font-size: 14px; margin-bottom: 8px; }
.is-smartphone .form-group input,
.is-smartphone .form-group textarea {
    font-size: 16px;
    padding: 12px 14px;
    border-radius: 12px;
}

.is-smartphone .sidebar-header h2 { font-size: 18px; }

.is-smartphone .chat-item {
    padding: 12px;
    min-height: 64px;
    border-radius: 12px;
    margin-bottom: 4px;
}

.is-smartphone .chat-item-name {
    font-size: 15px;
    font-weight: 500;
}

.is-smartphone .chat-item-preview {
    font-size: 13px;
    margin-top: 2px;
}

.is-smartphone .chat-item-avatar {
    width: 44px;
    height: 44px;
    font-size: 18px;
}

.is-smartphone .message-timestamp {
    font-size: 10px;
    opacity: 0.5;
}

.is-smartphone .world-entry {
    padding: 14px;
    border-radius: 12px;
}

.is-smartphone .world-entry-header {
    font-size: 14px;
    margin-bottom: 8px;
}

.is-smartphone #avatarPreview {
    width: 100px;
    height: 100px;
}

.is-smartphone .section-title {
    font-size: 13px;
    font-weight: 600;
    margin-top: 16px;
    margin-bottom: 12px;
}

.is-smartphone .sidebar-footer .btn {
    padding: 12px 16px;
    font-size: 14px;
    min-height: 48px;
}

.is-smartphone .emote-picker {
    width: calc(100vw - 20px);
    left: -5px;
    max-height: 320px;
}

.is-smartphone .emote-grid { grid-template-columns: repeat(2, 1fr); }

.is-smartphone .input-wrapper { gap: 6px; }

.is-smartphone .toast {
    bottom: calc(80px + 60px + env(safe-area-inset-bottom));
    left: 16px;
    right: 16px;
    width: auto;
    padding: 14px 20px;
    font-size: 14px;
    border-radius: 12px;
    transform: none;
}

.is-smartphone .action-btn {
    padding: 6px 12px;
    font-size: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-right: 4px;
}

.is-smartphone .typing-indicator {
    padding: 14px 18px;
}

.is-smartphone #searchModal .modal {
    max-height: 70vh;
}

.is-smartphone .app-container::after {
    content: '';
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    z-index: 50;
    background: linear-gradient(to right, rgba(99, 102, 241, 0.1), transparent);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.is-smartphone .app-container:not(.sidebar-open)::after {
    opacity: 1;
}

.is-smartphone .header-actions { gap: 4px; }
.is-smartphone .chat-header { overflow: visible; }
.is-smartphone .header-actions { overflow: visible; }
.is-smartphone .header-dropdown { overflow: visible; }

.is-smartphone .character-panel::before,
.is-smartphone .world-info-panel::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
}

.is-smartphone .character-panel .panel-header,
.is-smartphone .world-info-panel .panel-header {
    padding-top: 24px;
}



@keyframes fadeInOverlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 768px) {
    body {
        overflow: hidden;
    }

    body::after {
        opacity: 0.12;
    }

    .app-container {
        height: 100dvh;
    }

    .sidebar {
        width: min(88vw, 330px);
        min-width: 0;
        background: rgba(10, 13, 20, 0.97);
    }

    .sidebar-tabs {
        margin: 0 10px 8px;
    }

    .sidebar-tab {
        flex-direction: column;
        gap: 3px;
        font-size: 11px;
        min-height: 42px;
        padding: 6px 4px;
    }

    .chat-header {
        min-height: 64px;
        padding: 10px 12px;
    }

    .character-info {
        gap: 10px;
        min-width: 0;
    }

    .character-name {
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .character-avatar {
        width: 44px;
        height: 44px;
    }

    .messages-container {
        padding: 16px 10px calc(92px + 60px + env(safe-area-inset-bottom));
        gap: 10px;
    }

    .message {
        padding: 12px;
    }

    .message-body {
        padding-left: 44px;
    }

    .message-actions {
        margin-top: 10px;
        flex-wrap: wrap;
    }

    .input-area {
        padding: 8px 10px 10px;
    }

    .input-container {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 8px;
    }

    .tool-btn {
        min-width: 40px;
        height: 40px;
    }

    .send-btn {
        width: 46px;
        height: 46px;
    }

    .onboarding-state {
        width: 100%;
        min-height: auto;
        max-height: calc(100dvh - 370px);
        justify-content: flex-start;
        gap: 8px;
        padding: 14px;
        overflow-y: auto;
        margin: 0 auto 18px;
    }

    .messages-container.show-bg .onboarding-state {
        width: 100%;
        max-width: none;
        padding: 14px;
    }

    .onboarding-icon {
        justify-content: center;
    }

    .onboarding-icon img {
        width: 56px;
        height: 56px;
        margin-bottom: 0;
    }

    .onboarding-title,
    .onboarding-sub {
        text-align: center;
    }

    .onboarding-title {
        font-size: 22px;
    }

    .onboarding-sub {
        font-size: 13px;
        line-height: 1.35;
    }

    .onboarding-steps,
    .starter-kit-heading {
        justify-content: center;
    }

    .onboarding-steps {
        gap: 8px;
    }

    .onboarding-step {
        display: flex;
        align-items: center;
        gap: 10px;
        flex: none;
        width: 100%;
        min-width: 0;
        max-width: none;
        padding: 8px 10px;
        text-align: left;
    }

    .onboarding-step-num {
        width: 26px;
        height: 26px;
        margin: 0;
        flex: 0 0 26px;
    }

    .onboarding-step-text {
        font-size: 12px;
    }

    .onboarding-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        margin-top: 0;
        gap: 8px;
    }

    .onboarding-actions .btn {
        width: 100%;
        min-width: 0;
        min-height: 38px;
        padding: 8px 12px;
        font-size: 13px;
        white-space: nowrap;
    }

    .starter-kit-section {
        display: block;
        max-width: none;
        margin-top: 2px;
    }

    .starter-kit-heading {
        font-size: 11px;
        margin-bottom: 8px;
    }

    .starter-kit-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .starter-kit-card {
        min-height: 0;
        padding: 11px;
    }

    .starter-kit-description {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .ob-overlay {
        align-items: flex-start;
        padding: 12px;
    }

    .ob-card {
        max-height: calc(100dvh - 24px);
        padding: 22px 16px 16px;
        border-radius: 8px;
    }

    .ob-dots {
        margin-bottom: 18px;
    }

    .ob-title {
        font-size: 22px;
    }

    .ob-sub {
        font-size: 13px;
        line-height: 1.45;
        margin-bottom: 18px;
    }

    .ob-features,
    .ob-char-types,
    .ob-form,
    .ob-starter-kits {
        margin-bottom: 16px;
    }

    .ob-feature {
        padding: 10px;
    }

    .ob-char-types,
    .ob-starter-kits {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .ob-char-type {
        display: grid;
        grid-template-columns: 38px 1fr;
        column-gap: 10px;
        text-align: left;
        padding: 10px;
    }

    .ob-char-type-icon {
        grid-row: span 2;
        margin: 0;
    }

    .ob-footer {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .chat-item {
        margin-inline: 8px;
    }

    .message-body {
        padding-left: 40px;
    }

    .message-avatar {
        width: 34px;
        height: 34px;
    }

    .onboarding-icon img {
        width: 52px;
        height: 52px;
    }
}

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

.is-smartphone .platform-footer { display: none !important; }

/* Inline Edit & Swipe Styles */
.inline-edit-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(var(--bg-tertiary-rgb), 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-top: 4px;
}

.inline-edit-textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    font-family: inherit;
}

.inline-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

.inline-edit-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.inline-edit-btn.cancel {
    background: transparent;
    color: var(--text-secondary);
}

.inline-edit-btn.cancel:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.inline-edit-btn.save {
    background: var(--accent-color);
    color: white;
}

.inline-edit-btn.save:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.swipe-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.swipe-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.swipe-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

.swipe-indicator {
    font-size: 12px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}
